/**
  * @param array $config
  *
  * @return array
  */
 private function getJobConfig(array $config)
 {
     $helper = new Helper();
     if (isset($config['closure'])) {
         $config['closure'] = $this->getSerializer()->serialize($config['closure']);
     }
     return array_merge(['enabled' => 1, 'haltDir' => null, 'runOnHost' => $helper->getHost(), 'dateFormat' => 'Y-m-d H:i:s', 'schedule' => '* * * * *', 'output' => $this->logFile, 'maxRuntime' => null, 'runAs' => null], $config);
 }
Exemple #2
0
 /**
  * @return bool
  */
 protected function shouldRun()
 {
     if (!$this->config['enabled']) {
         return false;
     }
     if (($haltDir = $this->config['haltDir']) !== null) {
         if (file_exists($haltDir . DIRECTORY_SEPARATOR . $this->job)) {
             return false;
         }
     }
     $schedule = \DateTime::createFromFormat('Y-m-d H:i:s', $this->config['schedule']);
     if ($schedule !== false) {
         return $schedule->format('Y-m-d H:i') == date('Y-m-d H:i');
     }
     $cron = CronExpression::factory($this->config['schedule']);
     if (!$cron->isDue()) {
         return false;
     }
     $host = $this->helper->getHost();
     if (strcasecmp($this->config['runOnHost'], $host) != 0) {
         return false;
     }
     return true;
 }
Exemple #3
0
 /**
  * @covers ::getHost
  */
 public function testGetHostname()
 {
     $actual = $this->helper->getHost();
     $this->assertContains($actual, [gethostname(), php_uname('n')]);
 }