コード例 #1
0
ファイル: RunSingle.php プロジェクト: ingenerator/runsingle
 /**
  * @param string $task_name
  * @param string $command
  * @param string $timeout
  * @param string $garbage_collect
  *
  * @return integer
  */
 public function execute($task_name, $command, $timeout, $garbage_collect)
 {
     if ($garbage_collect === TRUE) {
         $this->logger->info('garbage collecting for task ' . $task_name);
         $this->driver->garbage_collect($task_name);
     }
     $this->logger->info('lock_holder id is ' . $this->lock_holder->get_lock_holder());
     $this->logger->info('trying to get lock for task ' . $task_name);
     $lock_id = $this->driver->get_lock($task_name, $timeout, $this->lock_holder->get_lock_holder());
     if ($lock_id !== FALSE) {
         $this->logger->info('executing task ' . $task_name . ' ...');
         $this->logger->info('<command output>');
         $start_time = time();
         $exit_code = $this->runner->execute($command);
         $end_time = time();
         $elapsed_time = $end_time - $start_time;
         $this->logger->info('</command output>');
         $this->logger->info('finished ' . $task_name . ' after ' . $elapsed_time . ' seconds with exit code ' . $exit_code);
         $this->driver->release_lock($task_name, $lock_id);
         return $exit_code;
     }
     $this->logger->info('no lock available for ' . $task_name);
     return 0;
 }
コード例 #2
0
 /**
  * @param \Ingenerator\RunSingle\LockDriver $driver
  * @param \Ingenerator\RunSingle\LockHolder $lock_holder
  */
 function it_passes_garbage_collect_option_to_get_lock_method($driver, $lock_holder)
 {
     $lock_holder->get_lock_holder()->willReturn('test');
     $this->subject->execute(self::TASK_NAME, self::COMMAND, self::TIMEOUT, FALSE);
     $driver->get_lock(self::TASK_NAME, self::TIMEOUT, 'test')->shouldHaveBeenCalled();
 }