Index: feeds/includes/FeedsScheduler.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/feeds/includes/FeedsScheduler.inc,v
retrieving revision 1.20
diff -u -r1.20 FeedsScheduler.inc
--- feeds/includes/FeedsScheduler.inc	19 Jun 2010 19:40:43 -0000	1.20
+++ feeds/includes/FeedsScheduler.inc	25 Aug 2010 12:47:22 -0000
@@ -101,6 +101,8 @@
 
     // Iterate over feed importers, pick $num jobs for each of them and
     // schedule them.
+    $jobs = array();
+    
     if ($importers = feeds_importer_load_all()) {
       $num = $this->queue() ? variable_get('feeds_schedule_queue_num', 200) : variable_get('feeds_schedule_num', 5);
       foreach ($importers as $importer) {
@@ -109,13 +111,28 @@
           if ($period != FEEDS_SCHEDULE_NEVER) {
             $result = db_query_range("SELECT feed_nid, id, callback, last_executed_time FROM {feeds_schedule} WHERE id = '%s' AND callback = '%s' AND scheduled = 0 AND (last_executed_time < %d OR last_executed_time = 0) ORDER BY last_executed_time ASC", $importer->id, $callback, FEEDS_REQUEST_TIME - $period, 0, $num);
             while ($job = db_fetch_array($result)) {
-              $this->schedule($job);
-              // @todo Add time limit.
+              $jobs[] = $job;
             }
           }
         }
       }
     }
+    
+    $batch = array(
+      'operations' => array(
+        array('_feeds_scheduler_process', array($obj, $jobs))
+      ),
+      'finished' => '_feeds_scheduler_finished',
+      'title' => t('Feeds Scheduler'),
+      'init_message' => t('Schedule is starting.'),
+      'progress_message' => t('Processed @current out of @total.'),
+      'error_message' => t('Batch has encountered an error.'),
+      'file' => drupal_get_path('module', 'feeds') . '/includes/FeedsSchedulerBatch.inc',
+    );
+    
+    batch_set($batch);
+    batch_process();
+    
     // Unflag and post a message that we're done.
     variable_set('feeds_scheduler_cron', FALSE);
     watchdog('FeedsScheduler', 'Finished processing schedule after !time.', array('!time' => format_interval(time() - $start)));
@@ -197,7 +214,7 @@
    * @param $job
    *   A job array.
    */
-   protected function schedule($job) {
+   public function schedule($job) {
      db_query("UPDATE {feeds_schedule} SET scheduled = %d WHERE id = '%s' AND feed_nid = %d AND callback = '%s'", FEEDS_REQUEST_TIME, $job['id'], $job['feed_nid'], $job['callback']);
      if (db_affected_rows()) {
        if ($this->queue()) {
Index: feeds/includes/FeedsSchedulerBatch.inc
===================================================================
RCS file: feeds/includes/FeedsSchedulerBatch.inc
diff -N feeds/includes/FeedsSchedulerBatch.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ feeds/includes/FeedsSchedulerBatch.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,42 @@
+<?php
+// $Id: FeedsSchedulerBatch.inc,v 1.0 2010/08/25 14:44:44 morningtime Exp $
+
+/**
+ * Implementation of hook_process()
+ */
+function _feeds_scheduler_process($obj, $jobs, &$context) {
+  if (!isset($context['sandbox']['progress'])) {
+    $context['sandbox']['progress'] = 0;
+    $context['sandbox']['max'] = count($jobs);
+  }
+  
+  // Execute job
+  $job = $jobs[$context['sandbox']['progress']];
+  feeds_scheduler()->schedule($job);
+  
+  $context['sandbox']['progress']++;
+
+  // Inform the batch engine that we are not finished,
+  // and provide an estimation of the completion level we reached.
+  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
+    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
+  }
+}
+
+/**
+ * Implementation of hook_finished()
+ */
+function _feeds_scheduler_finished($success, $results, $operations) {
+  if ($success) {
+    // Here we do something meaningful with the results.
+    $message  = count($results) .' processed.';
+    $message .= theme('item_list', $results);
+  }
+  else {
+    // An error occurred.
+    // $operations contains the operations that remained unprocessed.
+    $error_operation = reset($operations);
+    $message = t('An error occurred while processing %error_operation with arguments: @arguments', array('%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE)));
+  }
+  drupal_set_message($message);
+}
\ No newline at end of file
