本文整理匯總了PHP中CronTask::getSchedule方法的典型用法代碼示例。如果您正苦於以下問題:PHP CronTask::getSchedule方法的具體用法?PHP CronTask::getSchedule怎麽用?PHP CronTask::getSchedule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CronTask
的用法示例。
在下文中一共展示了CronTask::getSchedule方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: runTask
/**
* Checks and runs a single CronTask
*
* @param CronTask $task
* @param boolean $forceRun
*/
protected function runTask(CronTask $task, $forceRun = false)
{
$cron = Cron\CronExpression::factory($task->getSchedule());
$isDue = $this->isTaskDue($task, $cron);
$willRun = $isDue || $forceRun;
// Update status of this task prior to execution in case of interruption
CronTaskStatus::update_status(get_class($task), $willRun);
if ($isDue || $forceRun) {
$msg = ' will start now';
if (!$isDue && $forceRun) {
$msg .= " (forced run)";
}
$this->output(get_class($task) . $msg);
// Handle exceptions for tasks
$error = null;
try {
$result = $task->process();
$this->output(CronTaskResult::PrettifyResult($result));
} catch (Exception $ex) {
$result = false;
$error = $ex->getMessage();
$this->output(CronTaskResult::PrettifyResult($result));
}
// Store result if we return something
if (self::config()->store_results && $result !== null) {
$cronResult = new CronTaskResult();
if ($result === false) {
$cronResult->Failed = true;
$cronResult->Result = $error;
} else {
if (is_object($result)) {
$result = print_r($result, true);
} else {
if (is_array($result)) {
$result = json_encode($result);
}
}
$cronResult->Result = $result;
}
$cronResult->TaskClass = get_class($task);
$cronResult->ForcedRun = $forceRun;
$cronResult->write();
}
} else {
$this->output(get_class($task) . ' will run at ' . $cron->getNextRunDate()->format('Y-m-d H:i:s') . '.');
}
}
示例2: runTask
/**
* Checks and runs a single CronTask
*
* @param CronTask $task
*/
public function runTask(CronTask $task)
{
$cron = Cron\CronExpression::factory($task->getSchedule());
$isDue = $this->isTaskDue($task, $cron);
// Update status of this task prior to execution in case of interruption
CronTaskStatus::update_status(get_class($task), $isDue);
if ($isDue) {
$this->output(get_class($task) . ' will start now.');
$task->process();
} else {
$this->output(get_class($task) . ' will run at ' . $cron->getNextRunDate()->format('Y-m-d H:i:s') . '.');
}
}