Missed Tasks Handling

Besides possessing the conventional scheduler features (starting tasks at specified time or with specified frequency), nnCron provides the users an opportunity to manage so called missed tasks and reminders. Missed task is a task, which has not been ran at scheduled time because nnCron was not started or your PC was not turned on.

If your PC is not running 24 hours a day, you may want to use a special nnCron task option (RunMissed) when defining important tasks to launch the task at scheduled time or at the first opportunity if it was impossible to start the task at the scheduled time. If the task becomes missed, it will be started at the top of the first minute after nnCron startup. nnCron checks for missed tasks every crontab reloading.

Task option RunMissed and nncron.ini variable DefaultRunMissedTime: are used to manage missed tasks.

Let me show you an example. Let's assume, that user wants to delete temporary files on his local disks every Sunday at 23:30. There is how his task may looks like:

#( test_cleanup
Time: 30 23 * * 7 *
Action:
    START-APP: ñ:\utils\cleanup.exe
)#

There is one shortcoming of this task: temporary files will not be deleted for a two weeks if user's PC will be turned off on the next Sunday at 23:30. If the user does not want to wait for such a long time, he may want to turn on missed tasks handling:

#( test_cleanup1
RunMissed
Time: 30 23 * * 7 *
Action:
    START-APP: ñ:\utils\cleanup.exe
)#

Now, the task that was unable to start at Sunday, 23:30 will launch "at the first opportunity" - at the top of the first minute after nnCron startup, when user will turn his PC on: for example at Monday, 08:00.

There is an 'extended' RunMissed option: RunMissed: <hh:mm|days>. It allows you to specify maximum waiting time (in hours and minutes) that may elapse since this task was sheduled to run for the last time. The missed task will not be launched if specified waiting time value is smaller than the actual time elapsed since this task was sheduled to run for the last time.

Let's modify the previous example, to take all the benefits of RunMissed: <hh:mm|days> option. Now we want to start this task at specified time (every Sunday, 23:30) or at the first opportunity if the task becomes missed, but only if no more than 3 days are elapsed since the time the task was scheduled to run:

#( test_cleanup2
RunMissed: 3
Time: 30 23 * * 7 *
Action:
START-APP: ñ:\utils\cleanup.exe
)#

If the user turned his PC off at saturday evening and turned it on at tuesday the task will be executed immediately after nnCron startup. And if the user turns his PC at thursday or friday the task will not be launched because specified waiting time (3 days) is smaller that the actual time elapsed since this task was sheduled to run and nnCron will wait until the next scheduled time (next Sunday, 23:30).

You can use the RunMissed? word to check if the started task was missed and is started 'at the first opportunity' or it was started at the scheduled time. The word RunMissed? is mainly used to display a warning when launching missed task.

You can manage missed tasks handling using nnCron GUI: checkboxes to turn RunMissed option on/off and input fields to enter maximum waiting time are available in New Task, New Reminder

and Edit Task dialog boxes.


Info for the curious users: where nnCron stores the data that is needed for missed tasks handling?

nnCron stores all the data that is needed for missed tasks handling in a file etc\taskinfo.txt. Here is it's format:

Field Description
TI-NAME task name
TI-CRC32 name+time crc32
TI-CREATION-TIME time of crc32 creation
TI-WRITE-TIME reserved for future use
TI-EXECUTION-TIME time of task execution
TI-FLAG-SUCCESS 1 if the task was launched successfully
TI-FLAG-EXIST Special fileld, that is used for obsolete tasks removal. Should be set to 1.


Info for the curious users: how are time ranges handled during missed tasks management (say, Time: * 16-19 * * * *)?

First of all the latest assumed date when the task was scheduled to run for the last time is calculated. If there are several Time: constructs in the given task, we are choosing the time range with nearest (closest to the current time) right margin. Of course, if there is a single Time: construct, we are choosing the only available time range. Then we are comparing the assumed time when the task was scheduled to run with the left margin of the choosen time region. If the assumed time is smaller than the left margin of choosen time region, we are considering the task as missed and immediately starting it.

If the given task was never started before, we are examining the date when the task was created. Task creation time is compared with the right margin of the choosen time region. If the task creation time is smaller than the right margin of choosen time region, the task is considered missed as well and is immediately started.


See also: