Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Add a Cron or Scheduled task that executes at your lowest common interval (5 minutes? 1 minute?).</p> <p>The scheduled task should query a database table that holds info on the frequency of the user's task. I would express frequency in seconds, then use a UNIX timestamp to determine eligibility for execution. The computation is then somewhat easy:</p> <ul> <li>Find the current time, rounded down to nearest common interval (assuming a 60-second interval): NOW = TIMESTAMP - (TIMESTAMP % 60)</li> <li>Find users whose interval is an even divisor of the current time period</li> </ul> <p>The table could look like this:</p> <pre><code>CREATE TABLE `scheduled_tasks` ( `id` int(7) unsigned NOT NULL auto_increment, `user_id` int(7) unsigned NOT NULL, `task` varchar(32) NOT NULL, `interval` int(10) NOT NULL, `date_start` date NOT NULL default '0000-00-00', `date_end` date NOT NULL default '2030-12-31', -- Hopefully you won't be still maintaining this app PRIMARY KEY (`id`) ) ; INSERT INTO `scheduled_tasks` (user_id, task, interval, date_start, date_end ) VALUES (1, 'standard_job', 5*60, '2009-06-01', '2009-08-01'), (2, 'standard_job', 10*60, CURDATE(), CURDATE() ), (3, 'standard_job', 24*60*60, '2009-06-01', '2009-08-01') </code></pre> <p>To find jobs to run, this query could work:</p> <pre><code>SELECT `user_id`, `task` FROM `scheduled_tasks` WHERE (UNIX_TIMESTAMP() - (UNIX_TIMESTAMP() % 60 ) ) % `interval` = 0 AND CURDATE() BETWEEN `date_start` AND `date_end` </code></pre> <p>That comes back with a list of users/tasks to run. You can add multiple entries per user if necessary.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload