本文整理汇总了PHP中Cron\CronExpression::getNextRunDate方法的典型用法代码示例。如果您正苦于以下问题:PHP CronExpression::getNextRunDate方法的具体用法?PHP CronExpression::getNextRunDate怎么用?PHP CronExpression::getNextRunDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cron\CronExpression
的用法示例。
在下文中一共展示了CronExpression::getNextRunDate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkSchedule
public function checkSchedule()
{
$timestamp = microtime(true);
$hour = date('G');
if (is_numeric($this->schedule)) {
//If you need to perform at intervals, then check to see whether early to perform
if (isset($this->previousTime) && $timestamp <= $this->previousTime + $this->schedule) {
return;
}
$this->previousTime = $timestamp;
} else {
if (is_array($this->schedule)) {
if (isset($this->previousTime) && $this->previousTime == $hour || !in_array($hour, $this->schedule)) {
return;
}
$this->previousTime = $hour;
} else {
if (is_string($this->schedule)) {
$nextRunDate = false;
try {
//See https://github.com/mtdowling/cron-expression
if (!isset($this->cronExpression)) {
$this->cronExpression = CronExpression::factory($this->schedule);
}
$nextRunDate = $this->cronExpression->getNextRunDate();
} catch (\Exception $e) {
$this->terminate();
}
//first step always skipped
if (!isset($this->previousTime)) {
$this->previousTime = $nextRunDate;
}
if ($this->previousTime == $nextRunDate) {
return;
}
$this->previousTime = $nextRunDate;
} else {
//once
if (isset($this->previousTime)) {
return;
}
$this->previousTime = true;
}
}
}
//execute daemon now
try {
$this->daemon->run();
} catch (\Exception $e) {
$this->terminate();
}
}
示例2: getNextRunDate
/**
* Returns the timestamp of the next run date.
*
* @return int
*/
public function getNextRunDate()
{
if ($this->nextRunDate === null) {
$nextRun = $this->cronExpression->getNextRunDate();
$this->nextRunDate = $nextRun->getTimestamp();
}
return $this->nextRunDate;
}
示例3: isDue
/**
* Check if the job is due to run
*
* @return bool
*/
public function isDue()
{
if ($this->lastExecutionFile && is_readable($this->lastExecutionFile)) {
$lastExecution = file_get_contents($this->lastExecutionFile);
$lastRunDate = $this->execution->getPreviousRunDate('now', 0, true);
$nextRunDate = $this->execution->getNextRunDate();
echo (is_string($this->command) ? $this->command : '[function]') . ': ' . $lastExecution . ' | ' . $lastRunDate->getTimestamp() . ' | ' . $nextRunDate->getTimestamp() . "\n";
return $lastRunDate->getTimestamp() > $lastExecution && $this->truthTest === true;
}
return $this->execution->isDue() && $this->truthTest === true;
}
示例4: isScheduled
/**
* {@inheritdoc}
*/
public function isScheduled()
{
try {
$now = new \DateTime('now', $this->getTimeZone());
return $this->expression->getNextRunDate($now) instanceof \DateTime;
// @codeCoverageIgnoreStart
} catch (\Exception $exception) {
return false;
}
// @codeCoverageIgnoreEnd
}
示例5: testDeterminesIfCronIsDue
/**
* @covers Cron\CronExpression::isDue
* @covers Cron\CronExpression::getNextRunDate
* @covers Cron\CronExpression::unitSatisfiesCron
* @dataProvider scheduleProvider
*/
public function testDeterminesIfCronIsDue($schedule, $relativeTime, $nextRun, $isDue)
{
$cron = new CronExpression($schedule);
if (is_string($relativeTime)) {
$relativeTime = new \DateTime($relativeTime);
} else {
if (is_int($relativeTime)) {
$relativeTime = date('Y-m-d H:i:s', $relativeTime);
}
}
$this->assertEquals($isDue, $cron->isDue($relativeTime));
$this->assertEquals(new \DateTime($nextRun), $cron->getNextRunDate($relativeTime));
}
示例6: getScheduleTimes
/**
* {@inheritDoc}
*/
public function getScheduleTimes()
{
if (!$this->isScheduled()) {
return array();
}
$currentTime = new \DateTime();
try {
$startTime = $this->cronExpression->getNextRunDate($currentTime);
} catch (\RuntimeException $e) {
return array();
}
$endTime = clone $startTime;
$endTime->add(new \DateInterval($this->interval));
return array('start' => $startTime, 'end' => $endTime);
}
示例7: getNextDate
/**
* Get the n futur execution
*
* @param int $next Nombre iteration of the cron job in the futur
*
* @return null|String[]
*/
function getNextDate($next = 5)
{
$next_datetime = array();
if (!$this->_cron_expression) {
$this->getCronExpression();
}
try {
for ($i = 0; $i < $next; $i++) {
$next_datetime[] = $this->_cron_expression->getNextRunDate("now", $i, true)->format('Y-m-d H:i:s');
}
} catch (Exception $e) {
return null;
}
return $this->_next_datetime = $next_datetime;
}
示例8: isTaskDue
/**
* Determine if a task should be run
*
* @param CronTask $task
* @param CronExpression $cron
*/
public function isTaskDue(CronTask $task, CronExpression $cron)
{
// Get last run status
$status = CronTaskStatus::get_status(get_class($task));
// If the cron is due immediately, then run it
$now = new DateTime(SS_Datetime::now()->getValue());
if ($cron->isDue($now)) {
if (empty($status->LastRun)) {
return true;
}
// In case this process is invoked twice in one minute, supress subsequent executions
$lastRun = new DateTime($status->LastRun);
return $lastRun->format('Y-m-d H:i') != $now->format('Y-m-d H:i');
}
// If this is the first time this task is ever checked, no way to detect postponed execution
if (empty($status->LastChecked)) {
return false;
}
// Determine if we have passed the last expected run time
$nextExpectedDate = $cron->getNextRunDate($status->LastChecked);
return $nextExpectedDate <= $now;
}
示例9: getNextRunDate
/**
* @param string $currentTime
* @param int $nth
* @param bool|false $allowCurrentDate
* @return Carbon
*/
public function getNextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false)
{
return Carbon::instance(parent::getNextRunDate($currentTime, $nth, $allowCurrentDate));
}