/** * @return array A two-element array. Both elements are of boolean type. * First element is false if repeat count exceeds limit. * Otherwise - true. * Second element is false if repeat condition is not met. * Otherwise - true; */ public function start() { $count = 0; do { $result = $this->task->execute(); ++$count; $isInsideLimit = $this->_isInsideLimit($count); $repeat = $this->repeatCondition->isSatisfying($count, $result); } while ($isInsideLimit && $repeat); return [$isInsideLimit, $repeat]; }
/** * @param TaskInterface $task * * @return int */ private function runInSubProcess(TaskInterface $task) { if (!function_exists('pcntl_fork')) { $task->start(); return; } $pid = pcntl_fork(); if ($pid === -1) { // Зупускаем задачу в текущем потоке если не смогли создать форк $task->start(); } elseif (0 === $pid) { try { $task->start(); } catch (\Exception $e) { } exit; } }
/** * TODO * @param TaskInterface $task * @param string|\DateTime $time * @return boolean */ public function handle(TaskInterface $task, $time = 'now') { $cronExpression = CronExpression::factory($task->getExpression()); if ($cronExpression->isDue($time)) { $result = $this->execute($task->getCommand()); if ($result && $task->getRepeat() == false) { $task->deleteTask(); } return $result; } return false; }