Hi,

I have 7 feeds that I want to import automatically with Cron.

When I import the feeds manually by clicking on "Process", they work fine.

But when I do it with cron, it seems that not all feeds are processed. I have allowed import overlap, and checked specified time interval from 00:00 to 24:00.

Maybe there is some other module to automate this? Ideally I would like to set the order in which the feeds are processed, and put a 5 minute delay between each feed processing.

Thanks for any ideas!

Comments

Taesto’s picture

Status: Active » Fixed

I found a solution, will report here in case it helps someone:

With Elysia Cron API I added a cronapi function in feed_import_module to define one cron job for each feed.
Then it is easy in Elysia Cron to order the specific cron jobs for each feed. Now all feeds are run every fifteen minutes with no problem.

Sorin Sarca’s picture

Status: Fixed » Closed (fixed)

Yes, Elysia Cron is the best solution for cron import. In the next version I will add some drush commands to be able to import using OS cronjobs.

Taesto’s picture

I put this in feed_import_module by hand and it has worked well for the past days. There is probably a way to automatize the creation of the feed_import_myfeedx functions. I removed many of the checks of the original feed_import_cron function because with Elysia cron it is already possible to make sure that feeds are processed one after the other.

function feed_import_cronapi($op, $job = NULL) {
	$items['myfeed1'] = array(
		'description' => 'Process MyFeed1',
		'rule' => '*/15 * * * *', // Every 15 minutes
		 // i must call: feed_import_myfeed1
		'callback' => 'feed_import_myfeed1',		
	);
	$items['myfeed2'] = array(
		'description' => 'Process MyFeed2',
		'rule' => '*/15 * * * *', // Every 15 minutes
		 // i must call: feed_import_myfeed2
		'callback' => 'feed_import_myfeed2',		
	);
}
function feed_import_myfeed1() {           
	$feeds = FeedImport::loadFeeds(TRUE);				
	$last_feed = 'machinenameofmyfeed1';
	$feeds = $feeds[$last_feed];
	// Process feed.
	feed_import_import_items($feeds);
	// Change running status.			
	unset($feeds, $last_feed);	
	// Delete expired items.
	$ids = FeedImport::getExpiredItems(variable_get('feed_import_delete_items_per_cron', 300));
	feed_import_delete_items($ids);
	unset($ids);
}
function feed_import_myfeed2() {           
	$feeds = FeedImport::loadFeeds(TRUE);				
	$last_feed = 'machinenameofmyfeed2';
	$feeds = $feeds[$last_feed];
	// Process feed.
	feed_import_import_items($feeds);
	// Change running status.			
	unset($feeds, $last_feed);	
	// Delete expired items.
	$ids = FeedImport::getExpiredItems(variable_get('feed_import_delete_items_per_cron', 300));
	feed_import_delete_items($ids);
	unset($ids);
}
Anonymous’s picture

For me, cron doesn't trigger the importation of my feed. I used Elysia cron to set it up but even though Elysia reports that the cron job was run, the feed import was not processed. (i didn't use any custom php code)

Sorin Sarca’s picture

@Taesto

There is probably a way to automatize the creation

I'll look for one.

@ervit

For me, cron doesn't trigger the importation of my feed. I used Elysia cron to set it up but even though Elysia reports that the cron job was run, the feed import was not processed. (i didn't use any custom php code)

Please check settings for feed import
-make sure that "Cron import" is checked
-adjust settings for "When feeds can be imported", you may set it to "From time to time" and "Time between two imports at cron (seconds)" = 1 if you are using Elysia module
Also, don't forget to enable your feed to run at cron (click on Enable link in feed list if is disabled).

blake.thompson’s picture

Just on the off chance someone is looking for a more concise way to do several feeds

Edited to include longtom's correction

<?php
function hook_cronapi($op, $job = NULL) {
    $items['myfeed1'] = array(
        'description' => 'Process MyFeed1',
        'rule' => '*/15 * * * *', // Every 15 minutes
        'callback' => 'feed_import_function',
        'arguments' => array('feed_name1'),
        'weight' => -10,
    );
    $items['myfeed2'] = array(
        'description' => 'Process MyFeed2',
        'rule' => '*/15 * * * *', // Every 15 minutes
        'callback' => 'feed_import_function',
        'arguments' => array('feed_name1'),
        'weight' => -9,
    );
    return $items;
}
function feed_import_function($feed_name = '') {
    $feeds = FeedImport::loadFeeds(TRUE);
    if (isset($feeds[$feed_name]) && (!variable_get('feed_import_import_running', FALSE) || variable_get('feed_import_let_overlap', FALSE))) {
        variable_set('feed_import_last_imported_feed', $feed_name);
        variable_set('feed_import_last_executed_import', REQUEST_TIME);
        // Mark import as running.
        variable_set('feed_import_import_running', TRUE);
        // Process feed.
        feed_import_import_items($feeds[$feed_name]);
        // Change running status.
        variable_set('feed_import_import_running', FALSE);
        unset($feeds, $feed_name);
    }   
    // Delete expired items.
    $ids = FeedImport::getExpiredItems(variable_get('feed_import_delete_items_per_cron', 300));
    feed_import_delete_items($ids);
    unset($ids);
}
?>
longtom’s picture

Don't you need to 'return $items' in this code?

cdonner’s picture

Issue summary: View changes

Will this call the preprocessor function or do I have to call that myself as well, in addition to all the stuff? Why is there not a single entry point for running a feed that wraps all the checks and logic that needs to happen?

Never mind - this is 3 years old and does not apply. I am back at square 1. Amazing how such a simple task can become an insurmountable obstacle on this platform.

dureaghin’s picture

#6
I'm getting an Error "Class 'FeedImport' not found".