Henrik and others,
Here are my observations about Scheduling and some of my practices (which may or may not be BEST practices). Henrik, I think you will find answers to a couple of your questions in the following drivel.
In general:
I look at the Scheduling as a special Process that runs automatically about every 60 seconds.
Each Business Rule is processed, in order, 1 at a time until all Business Rules have been processed.
If it takes longer than 60 seconds for all Business Rules to be processed, the first Business Rule will be processed a second time even if the last Business Rule has not been processed yet. Just to be clear, the last Business Rule will still get processed. Just because the Scheduling has started another run, the first run of the Scheduling will still complete processing all of the Business Rules.
My System.
I have 20 processes that are essential to my system that run via the Scheduling.
Each process is contained in its own Business Rule, so the Scheduling has 20 Business Rules.
I want each of these processes to run as often as possible, so the Business Rules do not have any conditions and just 1 Action to execute one of the processes.
Some times, 1 or more of these processes take more the 60 seconds to complete.
If a process is currently running, I do not want this same process to be started again until the current run completes
To prevent a particular process from running multiple times concurrently, I have a BO (ControlRecord) that is used to keep track if process is running or not.
The system has 20 instances of the ControlRecord (1 for each process). The ControlRecord has the following attributes: "Type" which contains the process name, "Switch" which is a Yes/No attribute and indicates if the process is running or not and "TimeStarted" which is the date and time when the process was last started.
The first thing a process does is FIND the ControlRecord for this process and check the Switch. If the Switch is No, it gets set to Yes, the TimeStarted is set to the Current time and a sub-process is called to do the actual processing.
The last thing the process does is reset the Switch back to No.
I have a Query for the ControlRecord, so I can easily see which processes are currently running and when the last time each ran.
Some observations from the above.
Multiple processes can be running at the same time, which is OK as long as they are all different process types.
If a process is currently running the next time the Scheduling checks to see if it should run again, it will be skipped. In this system skipping a process is OK as long as it is currently running.
In this system, having a process run at a particular time down to the minute is dangerous because it is possible that the condition may not be checked during the 60 seconds when the condition would evaluate to true, or if the time was the only condition the process could run more than once because the condition was checked multiple times during the 60 seconds that the condition evaluates to true.
I also have another processes that needs to run once per day early in the morning. To accomplish that, I have the Business Rule for this process before the above Business Rules and this process has the following conditions that need to be true before the process run: IF CURRENT_HOUR >= 2 AND SystemSettings.LastTimeRun < CURRENT_DATE.
SystemSettings.LastTimeRun is the last time this process ran and gets updated to the CURRENT_DATE when this process starts. So this process will run anytime after 2 AM but will only run once a day.
Some issues I have run into
1) On rare occasions a process has run multiple times concurrently. This could happen if for example Proc01 is running, the Scheduling starts its next round and skips Proc01 and starts Proc02, but then Proc01 completes and Proc02 is started a second time because the Switch for Proc02 was checked before the Yes value was saved to the database.
2) If a process crashes because of an internal error, the Switch for that process never gets set back to No, so this process would never run again. For this situation, I have another process that runs about every 15 minutes and checks each ControlRecord. If the ControlRecord Switch is Yes and the ControlRecord TimeStarted is more than 30 minutes ago, the Switch is reset to No. Under normal processing, my processes should not take 30 minutes to complete.