/** * @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; }
/** * @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); }
/** * @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; }
/** * @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); }
/** * @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()); }
/** * @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()); }