public static function parse($file) { /*{{{*/ if (!file_exists($file) || filesize($file) === 0) { return false; } $data = json_decode(file_get_contents($file), true); self::$check_sum = md5(json_encode($data)); if (empty($data)) { return array(); } $execute_plan = array(); foreach ($data as $task) { $task = CronTask::createTask($task['task'], $task['user'], $task['id'], $task['running_user']); if ($task) { $execute_plan[] = $task; } } return $execute_plan; }
<?php include '../src/parser.php'; include '../src/task.php'; include '../src/date.php'; include '../src/exception.php'; include '../src/logger.php'; $task = "0 10 * * 2 (/usr/bin/lockf -t 0 /home/q/system/cloudopenapi/logs/clean.lock /usr/local/php/bin/php /home/q/system/cloudopenapi/src/task/tool/clean_expired_data.php) >> /dev/null 2>&1 &"; $task = CronTask::createTask($task, null, null, null); print_r($task);
function test_area_plan() { /*{{{*/ $rule = '*/5 10-21 * * * echo 1'; $date = new CronSimpleDate(strtotime('2013/03/31 2:05:00')); $task = CronTask::createTask($rule, $date); $date = new CronSimpleDate(strtotime('2013/03/31 11:05:00')); assert($task->isReady($date)); $task->setIsRunning($date); $date = new CronSimpleDate(strtotime('2013/03/31 4:10:00')); assert(!$task->isReady($date)); $date = new CronSimpleDate(strtotime('2013/03/31 11:14:00')); assert($task->isReady($date)); $task->setIsRunning($date); $date = new CronSimpleDate(strtotime('2013/03/31 11:19:00')); assert($task->isReady($date)); $task->setIsRunning($date); $date = new CronSimpleDate(strtotime('2013/03/31 11:23:00')); assert(!$task->isReady($date)); $date = new CronSimpleDate(strtotime('2013/03/31 11:24:00')); assert($task->isReady($date)); $task->setIsRunning($date); $date = new CronSimpleDate(strtotime('2013/04/2 11:23:00')); assert($task->isReady($date)); $task->setIsRunning($date); $date = new CronSimpleDate(strtotime('2013/03/31 22:19:00')); assert(!$task->isReady($date)); $rule = '* * 4-6 * * echo 1'; $date = new CronSimpleDate(strtotime('2013/03/03 1:10:11')); $task = CronTask::createTask($rule, $date); $date = new CronSimpleDate(strtotime('2013/03/03 1:11:00')); assert(!$task->isReady($date)); $date = new CronSimpleDate(strtotime('2013/03/04 1:11:00')); assert($task->isReady($date)); $task->setIsRunning($date); $date = new CronSimpleDate(strtotime('2013/03/07 1:11:00')); assert(!$task->isReady($date)); $rule = '4-5 * * * * echo 1'; $task = CronTask::createTask($rule); $date = new CronSimpleDate(strtotime('2013/03/03 1:4:00')); assert($task->isReady($date)); $task->setIsRunning($date); $date = new CronSimpleDate(strtotime('2013/03/03 1:5:00')); assert($task->isReady($date)); $task->setIsRunning($date); }