Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding scheduling support for individual sources

  • Loading branch information...
commit eeb9ba21c00d864c9b57b229d8012edb09bd01c5 1 parent 85ed4c8
@ircmaxell authored
Showing with 8 additions and 1 deletion.
  1. +8 −1 cron.php
View
9 cron.php
@@ -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()));
}
Please sign in to comment.
Something went wrong with that request. Please try again.