/** * Runs task and returns output * @param TaskInterface $task * @return string */ public static function runTask($task) { $run = $task->createTaskRun(); $run->setTaskId($task->getTaskId()); $run->setTs(date('Y-m-d H:i:s')); $run->setStatus(TaskRunInterface::RUN_STATUS_STARTED); $run->saveTaskRun(); $run_final_status = TaskRunInterface::RUN_STATUS_COMPLETED; ob_start(); $time_begin = microtime(true); $result = self::parseAndRunCommand($task->getCommand()); if (!$result) { $run_final_status = TaskRunInterface::RUN_STATUS_ERROR; } $output = ob_get_clean(); $run->setOutput($output); $time_end = microtime(true); $time = round($time_end - $time_begin, 2); $run->setExecutionTime($time); $run->setStatus($run_final_status); $run->saveTaskRun(); return $output; }
/** * Formats task for export into crontab file * @param TaskInterface $task * @param string $path * @param string $php_bin * @param string $input_file * @return string */ public static function getTaskCrontabLine($task, $path, $php_bin, $input_file) { $str = ''; $comment = $task->getComment(); if (!empty($comment)) { $str .= '#' . $comment . PHP_EOL; } if (TaskInterface::TASK_STATUS_ACTIVE != $task->getStatus()) { $str .= '#'; } list($class, $method, $args) = self::parseCommand($task->getCommand()); $exec_cmd = $php_bin . ' ' . $input_file . ' ' . $class . ' ' . $method . ' ' . implode(' ', $args); $str .= $task->getTime() . ' cd ' . $path . '; ' . $exec_cmd . ' 2>&1 > /dev/null'; return $str . PHP_EOL; }