Index: includes/FeedsScheduler.inc =================================================================== --- includes/FeedsScheduler.inc (revision 1036) +++ includes/FeedsScheduler.inc (working copy) @@ -88,20 +88,23 @@ * If drupal_queue is present, only pushes refresh tasks to queue and * returns. If drupal_queue is not available, works off tasks. */ - public function cron() { + public function cron($feed_name = NULL, $semaphore_type = NULL, $bypass_queue = FALSE) { // Check and set scheduler semaphore, take time. - if (variable_get('feeds_scheduler_cron', FALSE)) { + // Set semaphore for a cron or drush request. + $feeds_semaphore = $semaphore_type ? $semaphore_type : 'feeds_scheduler_cron'; + if (variable_get($feeds_semaphore, FALSE)) { watchdog('FeedsScheduler', 'Last cron process did not finish.', array(), WATCHDOG_ERROR); } - variable_set('feeds_scheduler_cron', TRUE); + variable_set($feeds_semaphore, TRUE); $start = time(); // Release schedule lock where the lock is older than 1 hour. db_query("UPDATE {feeds_schedule} SET scheduled = 0 WHERE scheduled < %d", FEEDS_REQUEST_TIME - 3600); + $importers = $feed_name ? array(feeds_importer($feed_name)) : feeds_importer_load_all(); // Iterate over feed importers, pick $num jobs for each of them and // schedule them. - if ($importers = feeds_importer_load_all()) { + if ($importers) { $num = $this->queue() ? variable_get('feeds_schedule_queue_num', 200) : variable_get('feeds_schedule_num', 5); foreach ($importers as $importer) { foreach ($importer->getScheduleCallbacks() as $callback) { @@ -109,7 +112,7 @@ 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); + $this->schedule($job, $bypass_queue); // @todo Add time limit. } } @@ -117,7 +120,7 @@ } } // Unflag and post a message that we're done. - variable_set('feeds_scheduler_cron', FALSE); + variable_set($feeds_semaphore, FALSE); watchdog('FeedsScheduler', 'Finished processing schedule after !time.', array('!time' => format_interval(time() - $start))); } @@ -195,10 +198,10 @@ * @param $job * A job array. */ - protected function schedule($job) { + protected function schedule($job, $bypass_queue = FALSE) { 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()) { + if ($this->queue() && !$bypass_queue) { if (!$this->queue()->createItem($job)) { $this->unschedule($job); watchdog('FeedsScheduler', 'Error adding item to queue.', WATCHDOG_CRITICAL);