For a site I'm working on, I'm heavily using feedapi to aggregate news for my site. I'm pulling and parsing enough feeds that I can see that running 1 cron job to handle everything really isn't going to be efficient. I've been searching for information on running different cron tasks at different time.

For example, I'm building a sports site that hits rss feeds for each individual team. Is there a way to set it so I have a cron that runs at 01 that grabs my nfl teams, 15 for baseball, 30 for basketball, and so forth and so on?

Comments

fronbow’s picture

As far as I know, there isn't a way to tell cron to run specific tasks at specific times.
Cron is just a scheduling mechanism.

Why not just set your cron job to run more frequently?

Alternatively, write a new version of cron.php that grabs the required stuff and then stick this file in your crontab?
So, in the root of your site you'd have cron.php set to run every 12 hours or whatever, cron-nfl.php to run at 01 minutes, cron-baseball.php to run at 15 minutes past the hour, etc

This could get a bit tricky though so I personally would just set the cron job to run more frequently at certain times of the day (like after the games are due to be played)

fronbow’s picture

As far as I know, there isn't a way to tell cron to run specific tasks at specific times.
Cron is just a scheduling mechanism.

Why not just set your cron job to run more frequently?

Alternatively, write a new version of cron.php that grabs the required stuff and then stick this file in your crontab?
So, in the root of your site you'd have cron.php set to run every 12 hours or whatever, cron-nfl.php to run at 01 minutes, cron-baseball.php to run at 15 minutes past the hour, etc

This could get a bit tricky though so I personally would just set the cron job to run more frequently at certain times of the day (like after the games are due to be played)

jbowman’s picture

I'd probably have to go with the option of separate cron tabs. It's a lot of feeds, and when I'm done, I don't think I'll get them all to run in one instance before php times out. I was hoping there was already something out there module wise for the other option you presented. Thanks for the response!

fronbow’s picture

The first thing I'd do is suggest it to the developers, (before you attempt the individual cron jobs)!!

Then write your separate cron files (using the original cron.php as a skeleton), but don't include the last line so, something like:

include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

The after this, I'd do something like

function nfl_feedapi_cron() {
  $result = db_query("SELECT nid FROM {feedapi} WHERE nid=%d ORDER BY checked ASC", $nid_of_the_nfl_feed);
  timer_start('feedapi_cron');
  while ($feed = db_fetch_object($result, $row++)) {
    feedapi_invoke_feedapi('load', $feed);
    $timeout = feedapi_invoke_feedapi('refresh', $feed, TRUE);
    if ($timeout == FEEDAPI_TIMEOUT) {
      break;
    }
  }
}

nfl_feedapi_cron();

where $nid_of_the_nfl_feed is, well, the nid of the needed feed

In theory, this should work, but it's totally untested. If it does work, then put this file in your crontab at the specified time

Let me know how you get on

Cheers