I have a PSOS (perform script on server) script, and it's important that there's only one instance running at any one time.
What's the simplest and/or most elegant way to do this?
- $$GlobalVariable that's set upon script start and cleared up on end. Problem: only works for single user systems.
- Global field in a table: same problem (since globals are unique to each user session).
- Boolean Field in a Table with single record: set field to "1" when script starts, and clear it upon exit. Problem: what if the script exits prematurely? then later scripts will never run.
- TimeStamp Field in a Table with single record: set field to current host timestamp when script starts, and clear it upon exit. If we know the script should only take 30 seconds to run, then we can have some intelligent logic to handle the case where a script failed to exit cleanly. e.g. "If the timestamp is within 1 minute, then don't run, but if the timestamp is more than 10 minutes ago, we assume the prior script exited"
It would be cool if we could use record locking to solve this, but what I think I really need is table-wise locking (because the script in question is one that deletes the entire contents of a table and then repopulates it.