Index: job_queue.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/job_queue/job_queue.install,v
retrieving revision 1.3
diff -u -r1.3 job_queue.install
--- job_queue.install	21 Jul 2008 00:16:30 -0000	1.3
+++ job_queue.install	1 Mar 2009 13:28:18 -0000
@@ -19,6 +19,7 @@
       'arguments' => array('type' => 'text', 'not null' => TRUE),
       'file' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
       'priority' => array('type' => 'int', 'not null' => TRUE, 'size' => 'tiny'),
+      'schedule' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
     ),
     'indexes' => array(
       'priority' => array('priority', 'jqid'),
@@ -60,3 +61,12 @@
 
   return $return;
 }
+
+function job_queue_update_6003() {
+  $return = array();
+
+  db_add_field($return, 'job_queue', 'schedule', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+
+  return $return;
+}
+
Index: job_queue.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/job_queue/job_queue.module,v
retrieving revision 1.7
diff -u -r1.7 job_queue.module
--- job_queue.module	18 Aug 2008 07:35:59 -0000	1.7
+++ job_queue.module	1 Mar 2009 13:27:30 -0000
@@ -71,7 +71,7 @@
  *   If TRUE, do not add the job to the queue if one with the same function and
  *   arguments already exists.
  */
-function job_queue_add($function, $description, $arguments = array(), $file = '', $no_duplicate = FALSE) {
+function job_queue_add($function, $description, $arguments = array(), $file = '', $no_duplicate = FALSE, $schedule = 0) {
   static $priorities;
 
   if (!isset($priorities[$function])) {
@@ -85,7 +85,7 @@
     }
   }
 
-  db_query("INSERT INTO {job_queue} (created, description, function, arguments, file, priority) VALUES (%d, '%s', '%s', '%s', '%s', %d)", time(), $description, $function, serialize($arguments), $file, $priorities[$function]);
+  db_query("INSERT INTO {job_queue} (created, description, function, arguments, file, priority) VALUES (%d, '%s', '%s', '%s', '%s', %d)", time(), $description, $function, serialize($arguments), $file, $priorities[$function], $schedule);
 }
 
 /**
@@ -95,7 +95,7 @@
  *   executing. FALSE if the queue was empty.
  */
 function job_queue_dequeue() {
-  $job = db_fetch_object(db_query_range('SELECT jqid, description, function, arguments, file FROM {job_queue} WHERE priority <> %d ORDER BY priority, jqid', JOB_QUEUE_DO_NOT_RUN, 0, 1));
+  $job = db_fetch_object(db_query_range('SELECT jqid, description, function, arguments, file FROM {job_queue} WHERE priority <> %d AND schedule < %d ORDER BY priority, jqid', JOB_QUEUE_DO_NOT_RUN, time(), 0, 1));
   if ($job === FALSE) {
     return FALSE;
   }
@@ -117,7 +117,7 @@
 }
 
 function job_queue_cron() {
-  $job_count = db_result(db_query('SELECT count(*) FROM {job_queue}'));
+  $job_count = db_result(db_query('SELECT count(*) FROM {job_queue} WHERE schedule < %d', time()));
   while ($job_count > 0 && job_queue_dequeue()) {
     if ((timer_read('page') / 1000) > (ini_get('max_execution_time') / 2)) {
       break; // Stop once we have used over half of the maximum execution time or exceeds the original number of jobs.
@@ -137,13 +137,15 @@
 
     $header = array(
       t('Created'),
+      t('Scheduled on'),
       t('Description'),
     );
-    $result = pager_query('SELECT created, description, arguments FROM {job_queue} ORDER BY priority, jqid', 20);
+    $result = pager_query('SELECT created, schedule, description, arguments FROM {job_queue} ORDER BY priority, jqid', 20);
     $rows = array();
     while ($job = db_fetch_object($result)) {
       $rows[] = array(
         format_date($job->created),
+        $job->schedule ? format_date($job->schedule) : t('Next cron run'),
         t($job->description, unserialize($job->arguments)),
       );
     }

