Skip to content

Commit

Permalink
Adding scheduling support for individual sources
Browse files Browse the repository at this point in the history
  • Loading branch information
ircmaxell committed Feb 7, 2012
1 parent 85ed4c8 commit eeb9ba2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cron.php
Expand Up @@ -11,10 +11,17 @@
$mapper = new ircmaxell\com\DataMappers\Post($mysqli);

foreach ($config['sources'] as $name => $config) {
$config += array('constructorArgs' => array());
$config += array('constructorArgs' => array(), 'frequency' => 0);
$sql = 'SELECT `value` FROM cron_info WHERE `name` = ?';
$result = $mysqli->query($sql, array($name . '_last_run'))->fetch_assoc();
if ($result && $result['value'] + $config['frequency'] > time()) {
continue;
}
$r = new ReflectionClass('\\ircmaxell\\com\\Models\\Source\\' . $name);
$source = $r->newInstanceArgs($config['constructorArgs']);
$data = $source->getLatestPosts(0, 10);
echo "Saving " . count($data) . " Items From $name\n";
$mapper->saveAll($data);
$sql = 'INSERT INTO `cron_info` (`name`, `value`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`);';
$mysqli->query($sql, array($name . '_last_run', time()));
}

0 comments on commit eeb9ba2

Please sign in to comment.