stop and start plugin

Posted on
Wed Jul 18, 2018 11:03 am
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: stop and start plugin

I did some some experimentation on this a while back whenever I had the WUnderground plugin writing a ton of columns and rows to a table... what it came down to is that changing a column type in Postgre in a high-volume environment is considered an unsafe operation.

Their recommended approach is to create a new table with the new structure, insert the data from old to new table, then drop old table and rename new. I started to look into adding this into the SQL Logger a while back but ended up abandoning it just due to lack of time and the infrequency that I encountered it.

Jay's point about transactional versus reporting structure is a very good point too... you could create basically a mini data warehouse -- update a non-SQL Logger table with data in the format you need for reporting, then trim off the transactional data in the SQL Logger's device table to a reasonable size/history.

Posted on
Wed Jul 18, 2018 3:37 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: stop and start plugin

A) the apple script is not depending on Indigo. If it works or not is a question for OSX. It runs completely outside indigo.

In a terminal it works like this:
Code: Select all
osascript  /path to script/reloadSQLLogger.scpt

from indigo:
Code: Select all
import subprocess
cmd = "/usr/bin/osascript /Users/karlwachs/indigo/reloadSQLLogger.scpt  &  "
subprocess.Popen(cmd, shell=True)
in an indigo action.
to avoid: "osascript is not allowed assistive access. (-1728)"
You need to give indigo and indigo server in "/preferences/ system/security" "assistive access"

B) I am happy with postgres and have otherwise absolutely no performance issues even with 32 GByte = 2 years of data

Karl

and the external script is:
Code: Select all
activate application "Indigo 7"
delay 1
tell application "System Events"
   tell process "Indigo 7"
      tell menu bar 1
         click menu bar item "Plugins"
         tell menu bar item "Plugins"
            click menu item "SQL logger" of menu 1
            tell menu item "SQL logger" of menu 1
               click menu item "Disable" of menu 1
            end tell
         end tell
      end tell
   end tell
end tell      
delay 30
activate application "Indigo 7"
delay 1
tell application "System Events"
   tell process "Indigo 7"
      tell menu bar 1
         click menu bar item "Plugins"
         tell menu bar item "Plugins"
            click menu item "SQL logger" of menu 1
            tell menu item "SQL logger" of menu 1
               click menu item "Enable" of menu 1
            end tell
         end tell
      end tell
   end tell
end tell      

Posted on
Wed Jul 18, 2018 3:57 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: stop and start plugin

You will still be able to run that AppleScript from Indigo since it doesn't target the Indigo Server (no need for the python wrapper) - just run it as an external file.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jul 18, 2018 5:07 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: stop and start plugin

the action actually looks like this: a little more that just call the applescript:
Code: Select all
import time, subprocess, os
plug = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.sql-logger")

try:
   sqlLoggerRestartTime = indigo.variables["sqlLoggerRestartTime"]
except:
   sqlLoggerRestartTime = indigo.variable.create("sqlLoggerRestartTime", "0")

lastRestart = float(sqlLoggerRestartTime.value)

if time.time() - lastRestart > 100:
   if plug.isEnabled():
      cmd = "/usr/bin/osascript /Users/karlwachs/indigo/restartWithDelaySQLlogger.scpt   &"
      subprocess.Popen(cmd, shell=True)
      indigo.variable.updateValue(sqlLoggerRestartTime,value=unicode(time.time()))
      indigo.server.log("restarting sql logger, last restart was "+ unicode(time.time() - lastRestart) + " secs ago")
      return
indigo.server.log("NOT  restarting sql logger, last restart was less than 5 minutes ago "+ unicode(time.time() - lastRestart) + " secs ago")

Posted on
Thu Jul 19, 2018 10:51 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: stop and start plugin

Yes, well, if you make it more complicated then clearly it won't work... :roll:

We just keep seeing people proposing completely unnecessary workarounds for AppleScript and we want to make it clear that in those circumstances it doesn't have to be complicated. Deprecating AppleScript will be painful enough without making it worse for no reason.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 4 guests