Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.672
diff -u -p -r1.672 system.module
--- modules/system/system.module	14 Mar 2009 23:01:37 -0000	1.672
+++ modules/system/system.module	23 Mar 2009 04:13:59 -0000
@@ -1571,6 +1571,8 @@ function system_cron() {
   foreach ($cache_tables as $table) {
     cache_clear_all(NULL, $table);
   }
+  // Work off scheduled tasks.
+  system_scheduler_work();
 }
 
 /**
@@ -2297,3 +2299,54 @@ function system_image_toolkits() {
     ),
   );
 }
+
+/**
+ * Job scheduler. Add a function callback to the queue for cron processing. 
+ * Once a function is processed, it will called again as soon as possible 
+ * after $minimum_period elapsed.
+ * 
+ * @param $callback
+ *   Callback function to be invoked by scheduler.
+ * @param $arguments
+ *   Arguments to be passed to callback function.
+ * @param $minimum_period
+ *   Minimum time between recurring calls to $callback. One of 
+ *   300 (5 minutes)
+ *   1800 (30 minutes)
+ *   3600 (1 hour)
+ *   43200 (12 hours)
+ *   86400 (24 hours)
+ */
+function system_scheduler_add($callback, $arguments, $minimum_period) {
+  if (!in_array($minimum_period, system_scheduler_get_schedules())) {
+    return FALSE;
+  }
+  $item = new stdClass();
+  $item->callback = $callback;
+  $item->arguments = $arguments;
+  $item->minimum_period = $minimum_period;
+  return queue_add('scheduler_' . $minimum_period, $item);
+}
+
+/**
+ * Worker function for job scheduler.
+ */
+function system_scheduler_work() {
+  $schedules = system_scheduler_get_schedules();
+  foreach ($schedules as $schedule) {
+    while ($item = queue_reserve('scheduler_' . $schedule, $schedule)) {
+      if (drupal_function_exists($item->callback)) {
+        call_user_func($item->callback, $item->arguments);
+      }
+    }
+  }
+}
+
+/**
+ *  Return an array of available schedules.
+ *
+ * @return unknown
+ */
+function system_scheduler_get_schedules() {
+  return array(300, 1800, 3600, 43200, 86400);
+}
\ No newline at end of file
