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


PHP CronExpression::isDue方法代码示例

本文整理汇总了PHP中Cron\CronExpression::isDue方法的典型用法代码示例。如果您正苦于以下问题:PHP CronExpression::isDue方法的具体用法?PHP CronExpression::isDue怎么用?PHP CronExpression::isDue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cron\CronExpression的用法示例。


在下文中一共展示了CronExpression::isDue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testIsDueHandlesDifferentDates

 /**
  * @covers Cron\CronExpression::isDue
  */
 public function testIsDueHandlesDifferentDates()
 {
     $cron = new CronExpression('* * * * *');
     $this->assertTrue($cron->isDue());
     $this->assertTrue($cron->isDue('now'));
     $this->assertTrue($cron->isDue(new \DateTime('now')));
     $this->assertTrue($cron->isDue(date('Y-m-d H:i')));
 }
开发者ID:DaveNascimento,项目名称:civicrm-packages,代码行数:11,代码来源:CronExpressionTest.php

示例2: 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

示例3: execute

 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->logPath = $input->getOption('log');
     $cronInfoUrl = sprintf('http://%s:%d/info/cron/', $input->getOption('host'), $input->getOption('port'));
     $response = json_decode($this->curlRequest->getCurlResult($cronInfoUrl, [CURLOPT_TIMEOUT_MS => 100000])['body'], true);
     if (!is_array($response)) {
         $this->log('Core connection failed, exiting');
         throw new \RuntimeException('Error connecting to core server');
     }
     foreach ($response as $cronItem) {
         $this->cronExpression->setExpression(Ar::get($cronItem, 'time'));
         if ($this->cronExpression->isDue()) {
             $this->log('Executing: ' . Ar::get($cronItem, 'type'));
             switch (Ar::get($cronItem, 'type')) {
                 case 'playbook':
                     $url = sprintf('http://%s:%d/playbook/run/', $input->getOption('host'), $input->getOption('port'));
                     $playbookFile = Ar::get($cronItem, 'playbook');
                     $playbook = $this->fileLoader->load($playbookFile);
                     $this->curlRequest->getCurlResult($url, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => ['playbook' => urlencode($playbook), 'filename' => $playbookFile], CURLOPT_TIMEOUT_MS => 100000]);
                     $this->log('Executed playbook: ' . $playbookFile);
                     break;
                 case 'command':
                     $url = sprintf('http://%s:%d/command/run/', $input->getOption('host'), $input->getOption('port'));
                     $command = Ar::get($cronItem, 'command');
                     if (null === $command) {
                         break;
                     }
                     $this->curlRequest->getCurlResult($url, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => ['command' => urlencode($command)], CURLOPT_TIMEOUT_MS => 100000]);
                     $this->log('Executed command: ' . $command);
                     break;
                 case 'curl':
                     break;
             }
         }
     }
 }
开发者ID:evgeny-zinder,项目名称:slack-bot,代码行数:41,代码来源:CronWorkerCommand.php

示例4: 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

示例5: isDue

 /**
  * Check if the job is due to run
  *
  * @return bool
  */
 public function isDue()
 {
     return $this->execution->isDue() && $this->truthTest === true;
 }
开发者ID:peppeocchi,项目名称:php-cron-scheduler,代码行数:9,代码来源:Job.php


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