getHost() public method

public getHost ( ) : string
return string
Beispiel #1
0
 /**
  * @return bool
  */
 protected function shouldRun()
 {
     if (!$this->config['enabled']) {
         return false;
     }
     if ($this->config['haltDir'] !== null) {
         $flag_file = $this->config['haltDir'] . DIRECTORY_SEPARATOR . $this->job;
         if (file_exists($flag_file)) {
             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;
 }
Beispiel #2
0
 /**
  * @param array $config
  * @return array
  */
 private function getJobConfig(array $config)
 {
     $helper = new Helper();
     if ($config['command'] instanceof \Closure) {
         $config['command'] = $helper->closureToString($config['command']);
     }
     return array_merge(array("enabled" => 1, "haltDir" => null, "runOnHost" => $helper->getHost(), "dateFormat" => "Y-m-d H:i:s", "schedule" => "* * * * *", "output" => $this->logFile, "maxRuntime" => null), $config);
 }
Beispiel #3
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;
         }
     }
     $host = $this->helper->getHost();
     if (strcasecmp($this->config['runOnHost'], $host) != 0) {
         return false;
     }
     return true;
 }
Beispiel #4
0
 /**
  * @param array $config
  *
  * @return array
  */
 private function getJobConfig(array $config)
 {
     $helper = new Helper();
     if ($config['command'] instanceof \Closure) {
         $config['command'] = $helper->closureToString($config['command']);
     }
     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);
 }
 /**
  * @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);
 }
Beispiel #6
0
 /**
  * @covers ::sendMail
  * @covers ::getCurrentMailer
  */
 public function testSendMail()
 {
     $mailer = $this->getSwiftMailerMock();
     $mailer->expects($this->once())->method('send');
     $jobby = new Jobby();
     $config = $jobby->getDefaultConfig();
     $config['output'] = 'output message';
     $config['recipients'] = 'a@a.com,b@b.com';
     $helper = new Helper($mailer);
     $mail = $helper->sendMail('job', $config, 'message');
     $host = $helper->getHost();
     $email = "jobby@{$host}";
     $this->assertContains('job', $mail->getSubject());
     $this->assertContains("[{$host}]", $mail->getSubject());
     $this->assertEquals(1, count($mail->getFrom()));
     $this->assertEquals('jobby', current($mail->getFrom()));
     $this->assertEquals($email, current(array_keys($mail->getFrom())));
     $this->assertEquals($email, current(array_keys($mail->getSender())));
     $this->assertContains($config['output'], $mail->getBody());
     $this->assertContains('message', $mail->getBody());
 }
Beispiel #7
0
 /**
  * @covers Jobby\Helper::sendMail
  * @covers Jobby\Helper::getCurrentMailer
  */
 public function testSendMail()
 {
     $mailer = $this->getSwiftMailerMock();
     $mailer->expects($this->once())->method("send");
     $jobby = new Jobby();
     $config = $jobby->getDefaultConfig();
     $config["output"] = "output message";
     $config["recipients"] = "a@a.com,b@b.com";
     $helper = new Helper($mailer);
     $mail = $helper->sendMail("job", $config, "message");
     $host = $helper->getHost();
     $email = "jobby@{$host}";
     $this->assertContains("job", $mail->getSubject());
     $this->assertContains("[{$host}]", $mail->getSubject());
     $this->assertEquals(1, count($mail->getFrom()));
     $this->assertEquals("jobby", current($mail->getFrom()));
     $this->assertEquals($email, current(array_keys($mail->getFrom())));
     $this->assertEquals($email, current(array_keys($mail->getSender())));
     $this->assertContains($config["output"], $mail->getBody());
     $this->assertContains("message", $mail->getBody());
 }