getPlatform() public method

public getPlatform ( ) : integer
return integer
 /**
  * @covers ::checkMaxRuntime
  */
 public function testCheckMaxRuntimeShouldFailIsExceeded()
 {
     if ($this->helper->getPlatform() !== Helper::UNIX) {
         $this->markTestSkipped("'maxRuntime' is not supported on Windows");
     }
     $helper = $this->getMock('Jobby\\Helper', ['getLockLifetime']);
     $helper->expects($this->once())->method('getLockLifetime')->will($this->returnValue(2));
     $this->runJob(['command' => 'true', 'maxRuntime' => 1], $helper);
     $this->assertContains('MaxRuntime of 1 secs exceeded! Current runtime: 2 secs', $this->getLogContent());
 }
Beispiel #2
0
 /**
  * @covers ::getLockLifetime
  */
 public function testGetLocklifetime()
 {
     if ($this->helper->getPlatform() === Helper::WINDOWS) {
         $this->markTestSkipped("Test relies on posix_ functions");
     }
     $this->helper->acquireLock($this->lockFile);
     $this->assertEquals(0, $this->helper->getLockLifetime($this->lockFile));
     sleep(1);
     $this->assertEquals(1, $this->helper->getLockLifetime($this->lockFile));
     sleep(1);
     $this->assertEquals(2, $this->helper->getLockLifetime($this->lockFile));
     $this->helper->releaseLock($this->lockFile);
 }
Beispiel #3
0
 /**
  * Run all jobs.
  */
 public function run()
 {
     $isUnix = $this->helper->getPlatform() === Helper::UNIX;
     if ($isUnix && !extension_loaded('posix')) {
         throw new Exception('posix extension is required');
     }
     foreach ($this->jobs as $job => $config) {
         if ($isUnix) {
             $this->runUnix($job, $config);
         } else {
             $this->runWindows($job, $config);
         }
     }
 }
Beispiel #4
0
 /**
  * Run all jobs.
  */
 public function run()
 {
     $isUnix = $this->helper->getPlatform() === Helper::UNIX;
     if ($isUnix && !extension_loaded('posix')) {
         throw new Exception('posix extension is required');
     }
     $scheduleChecker = new ScheduleChecker();
     foreach ($this->jobs as $job => $config) {
         if (!$scheduleChecker->isDue($config['schedule'])) {
             continue;
         }
         if ($isUnix) {
             $this->runUnix($job, $config);
         } else {
             $this->runWindows($job, $config);
         }
     }
 }
Beispiel #5
0
 /**
  *
  */
 protected function runFile()
 {
     // If job should run as another user, we must be on *nix and
     // must have sudo privileges.
     $isUnix = $this->helper->getPlatform() === Helper::UNIX;
     $useSudo = "";
     if ($isUnix) {
         $hasRunAs = !empty($this->config["runAs"]);
         $isRoot = posix_getuid() === 0;
         if ($hasRunAs && $isRoot) {
             $useSudo = "sudo -u {$this->config['runAs']}";
         }
     }
     // Start execution. Run in foreground (will block).
     $command = $this->config['command'];
     $logfile = $this->getLogfile() ?: '/dev/null';
     exec("{$useSudo} {$command} 1>> \"{$logfile}\" 2>&1", $dummy, $retval);
     if ($retval !== 0) {
         throw new Exception("Job exited with status '{$retval}'.");
     }
 }
Beispiel #6
0
 /**
  * @covers ::getPlatform
  */
 public function testGetPlatform()
 {
     $actual = $this->helper->getPlatform();
     $this->assertContains($actual, [Helper::UNIX, Helper::WINDOWS]);
 }
Beispiel #7
0
 private function getSleepTime()
 {
     return $this->helper->getPlatform() === Helper::UNIX ? 1 : 2;
 }