Page 1 of 1

How to avoid Time script to overlap

Posted: Monday 30 January 2017 9:14
by emme
Ciao,

I have few time script that runs for more than 1 minute (they ping some devices and retry if they are not availble... so it could take time)

Because it is supposed to trigger switches in Domoticz, I have the issue that the script runs twice because a minute pass and it strats while the old one is still running.

This results in double actions... I don't like it!

So, unless there is no a clear way to avoid a script to run in case it has not finished yet, I create a not-so-complex workaround I'm going to show you:

Example:
script_time_dostuff.lua

Code: Select all

commandArray = {}
   os.execute('sleep 65')
return commandArray
..so this would overlap in the next minute

SOLUTION:
CREATE:
string variable called dostuff_running (0-not running, 1-running)
script_time_dostuff_running.lua

Code: Select all

commandArray = {}
   os.execute('sleep 2') --this to ensure the other script starts   
   if uservariables['dostuff_running'] == '0' then commandArray['Variable:dostuff_running'] = '1'
return commandArray
EDIT script_time_dostuff.lua as follow:

Code: Select all

commandArray = {}
   if uservariables['dostuff_running'] == '0'  then 
      os.execute('sleep 65')
   end
   commandArray['Variable:dostuff_running'] = '0'
return commandArray
of course... the script could run once every 2 minutes in the worst case, but if it takes less that 60secs, it will run correctly the next minute

ciao
M

Re: How to avoid Time script to overlap

Posted: Monday 30 January 2017 20:05
by jvdz
In genreral my comment would be NOT to do this with the TIME event, but rather run the script with CRON which will update the switch status by means of a JSON call.

Jos