Page 1 of 1

Scripting / tasks - Single threading certain tasks?

Posted: Tue Sep 30, 2003 6:41 am
by JonFo
Hi Everyone,



While it's a really neat feature that HB let's one run multiple scripts and tasks concurrently, I do have an occasional need to ensure that only one script of a paticular set is run at any given time.



My example relates to power control. I have a group of taks that turn the system on or off or cycle portions of it. However, these are all mutually exclusive as far as runtime goes. Don't want power on running at the same time power off is running :wink:



Therefore, is there any way to have a task or a script look at a group property to determine if one of its peers is currently running and skip this run request?



Thanks,

Posted: Tue Sep 30, 2003 8:51 am
by ScottBot
Jonathan,



One way to do this is to use global variables to keep the running state of the various groups.



For example, create a "Null Device" and add Properties to it to store the states for the various groups. When a script runs, have it set the Null Device Property value to "Running" (or whatever) and reset it to "Stopped" when completed. The script that starts the Script Device can also test to make sure the Property Value is "Stopped" before executing any of the scripts in that group. You could also test for the state in the Script instead of the Task, it just depends on the particular application.



You could also just check the "State" Property of each of the scripts in the group in a Task before executing anything. If they are all set to "Stopped", you know that nothing is running and it is safe to start a script.



If you have multiple Tasks to manage the scripts, you may run the risk of having more than one Task executing at the same time. This would create a small window where they may both execute scripts from the same group (very unlikely, but technically possible). If you can include all of the logic into a single Task, this will prevent this from happening, since a Task can not be executed again until it has completed.



Scott