当前位置: 首页>>代码示例>>PHP>>正文


PHP CronExpression::getNextRunDate方法代码示例

本文整理汇总了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();
     }
 }
开发者ID:pilat,项目名称:daemonizer,代码行数:52,代码来源:ChildController.php

示例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;
 }
开发者ID:olivier1980,项目名称:alpharpc,代码行数:13,代码来源:Schedule.php

示例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;
 }
开发者ID:smichaelsen,项目名称:php-cron-scheduler,代码行数:16,代码来源:Job.php

示例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
 }
开发者ID:juliangut,项目名称:janitor,代码行数:14,代码来源:Cron.php

示例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));
 }
开发者ID:DaveNascimento,项目名称:civicrm-packages,代码行数:19,代码来源:CronExpressionTest.php

示例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);
 }
开发者ID:juliangut,项目名称:zf-maintenance,代码行数:18,代码来源:CrontabProvider.php

示例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;
 }
开发者ID:fbone,项目名称:mediboard4,代码行数:22,代码来源:CCronJob.class.php

示例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;
 }
开发者ID:botzkobg,项目名称:silverstripe-crontask,代码行数:28,代码来源:CronTaskController.php

示例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));
 }
开发者ID:Talonon,项目名称:cron-expression-carbon,代码行数:10,代码来源:CronExpression.php


注:本文中的Cron\CronExpression::getNextRunDate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。