Page 1 of 2

how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 11:17 am
by kw123
Has someone figured out how to run eg a script (or action ...) only ONCE at startup?

setting a variable to "started" does not work as you need to reset it when indigo shuts down .. and there is no mechanism for that either ..

anyway looking for suggestions.


Karl

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 11:28 am
by Colorado4Wheeler
Why not write a file to the filesystem?

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 11:38 am
by jay (support)

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 2:20 pm
by Colorado4Wheeler
jay (support) wrote:

Wow, I didn't even know that was a thing. I love learning new tricks.

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 3:01 pm
by jay (support)
Colorado4Wheeler wrote:
jay (support) wrote:

Wow, I didn't even know that was a thing. I love learning new tricks.


LOL - been in there since Indigo 2 I believe.

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 3:25 pm
by Colorado4Wheeler
While I would like to know every last possible thing that I can code into Indigo, I'm not you :shock: :lol:. Besides, that's a pretty obscure little technique that I bet hasn't been used by many and glazed over by most when reading the docs :roll: :wink: .

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 3:41 pm
by jay (support)
Colorado4Wheeler wrote:
While I would like to know every last possible thing that I can code into Indigo, I'm not you :shock: :lol:. Besides, that's a pretty obscure little technique that I bet hasn't been used by many and glazed over by most when reading the docs :roll: :wink: .


Actually, it's probably the best way to start up stay-open scripts (things that query data sources, populate variables, etc.) that should pretty much always be running while the server is running. We recommended it for background scripts like the old iTunes Sync script for example.

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 4:43 pm
by kw123
thats great !!

Now how about when indigo shuts down ..

how about a basic plugin that runs, does nothing, Only when indigo shuts it down it does an action when
Code: Select all
try:
  while True:
       time.sleep(10)
except: pass

###do the action here


would that work?

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 5:10 pm
by jay (support)
Or implement the shutdown() method:

Code: Select all
def shutdown(self):
     # do any cleanup necessary before exiting


It would just have to do whatever it wanted to do quickly since I think we only wait for a plugin to shut down gracefully for 10 seconds.

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 5:14 pm
by kw123
Can shutdown() still call/ execute an indigo action ?


Sent from my iPhone using Tapatalk

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Wed Apr 25, 2018 10:09 pm
by kw123
Yes it can and it works fine.
Have written a plugin if anyone is interested



Sent from my iPhone using Tapatalk

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Thu Apr 26, 2018 5:42 am
by DaveL17
I never thought about using shutdown() with a server shutdown, but that makes sense. Do running plugins always shut down in alphabetical order? If that's the case, would "zzzPlugin" be "guaranteed" last to go?

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Thu Apr 26, 2018 8:50 am
by jay (support)
DaveL17 wrote:
I never thought about using shutdown() with a server shutdown, but that makes sense. Do running plugins always shut down in alphabetical order? If that's the case, would "zzzPlugin" be "guaranteed" last to go?


First, remember that shutdown() will also be called if the plugin is disabled or restarted - so you're not guaranteed that the server is also shutting down.

There is no explicit order of plugin shutdowns (that is, there is an order, but we don't publish it because it probably will change periodically as we do more backend server work so you shouldn't assume there is).

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Thu Apr 26, 2018 8:54 am
by DaveL17
Thanks Jay. Then the trigger seems like the best bet to key on a server shutdown.


Sent from my iPhone using Tapatalk

Re: how to run a script ONLY ONCE at start of indigo

PostPosted: Thu Apr 26, 2018 9:04 am
by jay (support)
Unfortunately, at the moment there isn't a Server Shutdown trigger that corresponds to the Server Startup trigger. It's been on the list for many years, but just doesn't seem to have a very high demand.