Skip to content
Snippets Groups Projects
Commit 83f1a1d4 authored by klausi's avatar klausi Committed by Chris Leppanen
Browse files

Issue #1231332 by klausi, twistor | nyl auster: Periodic import imports only one file per cron.

parent 0ba4a84a
No related branches found
No related tags found
No related merge requests found
...@@ -96,6 +96,7 @@ function feeds_cron_queue_info() { ...@@ -96,6 +96,7 @@ function feeds_cron_queue_info() {
$queues = array(); $queues = array();
$queues['feeds_source_import'] = array( $queues['feeds_source_import'] = array(
'worker callback' => 'feeds_source_import', 'worker callback' => 'feeds_source_import',
'time' => 60,
); );
$queues['feeds_source_clear'] = array( $queues['feeds_source_clear'] = array(
'worker callback' => 'feeds_source_clear', 'worker callback' => 'feeds_source_clear',
......
...@@ -290,19 +290,23 @@ class FeedsSource extends FeedsConfigurable { ...@@ -290,19 +290,23 @@ class FeedsSource extends FeedsConfigurable {
if (is_numeric($fetcher_period)) { if (is_numeric($fetcher_period)) {
$period = $fetcher_period; $period = $fetcher_period;
} }
// Schedule as soon as possible if a batch is active.
$period = $this->progressImporting() === FEEDS_BATCH_COMPLETE ? $period : 0;
$job = array( $job = array(
'type' => $this->id, 'type' => $this->id,
'id' => $this->feed_nid, 'id' => $this->feed_nid,
'period' => $period, 'period' => $period,
'periodic' => TRUE, 'periodic' => TRUE,
); );
if ($period != FEEDS_SCHEDULE_NEVER) { if ($period == FEEDS_SCHEDULE_NEVER) {
JobScheduler::get('feeds_source_import')->remove($job);
}
elseif ($this->progressImporting() === FEEDS_BATCH_COMPLETE) {
JobScheduler::get('feeds_source_import')->set($job); JobScheduler::get('feeds_source_import')->set($job);
} }
else { else {
JobScheduler::get('feeds_source_import')->remove($job); // Feed is not fully imported yet, so we put this job back in the queue
// immediately for further processing.
$queue = DrupalQueue::get('feeds_source_import');
$queue->createItem($job);
} }
} }
......
...@@ -227,23 +227,17 @@ class FeedsSchedulerTestCase extends FeedsWebTestCase { ...@@ -227,23 +227,17 @@ class FeedsSchedulerTestCase extends FeedsWebTestCase {
db_query("UPDATE {job_schedule} SET next = 0"); db_query("UPDATE {job_schedule} SET next = 0");
$this->drupalPost('import/node/delete-items', array(), 'Delete'); $this->drupalPost('import/node/delete-items', array(), 'Delete');
$this->assertEqual(0, db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")->fetchField()); $node_count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")->fetchField();
$this->assertEqual(0, $node_count);
// Hit cron (item count / limit) times, assert correct number of articles. // Hit cron for importing, until we have all items.
for ($i = 0; $i < ceil(86 / $limit); $i++) { while ($node_count < 86) {
$this->cronRun(); $this->cronRun();
sleep(1); $node_count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")->fetchField();
if ($limit * ($i + 1) < 86) {
$count = $limit * ($i + 1);
$period = 0; // Import should be rescheduled for ASAP.
}
else {
$count = 86; // We've reached our total of 86.
$period = 1800; // Hence we should find the Source's default period.
}
$this->assertEqual($count, db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")->fetchField());
$this->assertEqual($period, db_query("SELECT period FROM {job_schedule} WHERE type = 'node' AND id = 0")->fetchField());
} }
$this->assertEqual(86, db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")->fetchField(), 'Number of nodes is correct after batched importing via cron.');
// Import should be rescheduled for 1800 seconds.
$this->assertEqual(1800, db_query("SELECT period FROM {job_schedule} WHERE type = 'node' AND id = 0")->fetchField());
} }
// Delete a couple of nodes, then hit cron again. They should not be replaced // Delete a couple of nodes, then hit cron again. They should not be replaced
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment