本文整理汇总了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') . '.');
}
}