SCHED Library
The SCHED library is a helpful library for scheduling a process to run once a day, week, or month at a specific hour of day when used in conjunction with the component timer. This is useful for running batch processes.
Use the SCHEDrunAt() function to specify when a function or process should execute. Additional arguments can be passed for the function that will be called.
When run for the first time, the function will execute the batch process once and store the last run time in a text file ( <COMPONENT NAME>_LastScheduledTime.txt) in the working directory. Subsequent calls will check the current time and compare it with the scheduled run time and last run time. This means that a smaller component polling interval will result in a more timely execution.
Daily (simple format)
-- Example 1: Daily at 11:30 AM (backward compatible - original v6 format)
SCHEDrunAt(11.5, DoBatchProcess, "Some Argument", "Second Argument", "etc...")
Daily (table format)
-- Example 2: Daily at 11:30 AM (table format)
SCHEDrunAt({type="daily", hour=11.5}, DoBatchProcess, "Some Argument", "Second Argument", "etc...")
Weekly
-- Example 3: Weekly - Every Monday at 9 AM
SCHEDrunAt({type="weekly", weekday=2, hour=9}, DoBatchProcess, "Some Argument", "Second Argument", "etc...")
Monthly
-- Example 4: Monthly - First Monday of the month at 9 AM
SCHEDrunAt({type="monthly", weekday=2, occurrence=1, hour=9}, DoBatchProcess,"Some Argument", "Second Argument", "etc...")
Note: In the event the scheduled day doesn't exist in the month (e.g. the 4th Monday would be the 29th of February), the library will rollover to the next month (4th Monday of March).