示例#1
0
 public function run(JobName $jobName, JobSettings $settings, UuidInterface $previousEventId = null)
 {
     $jobWorker = $this->jobWorkerRepository->get($jobName);
     $this->processManager->onTermination([$jobWorker, 'stop']);
     $work = $jobWorker->start($this->eventProcessor, $settings, $previousEventId);
     foreach ($work as $event) {
         $this->jobWorkerRepository->save($jobWorker);
         $this->processManager->dispatchSignals();
     }
     $this->jobWorkerRepository->save($jobWorker);
 }
示例#2
0
 /**
  * @param Job[] $jobs
  */
 private function terminate(array $jobs)
 {
     // Stop all jobs
     foreach ($jobs as $job) {
         $job->stop($this->processManager);
     }
     // Wait until all jobs are terminated
     foreach ($jobs as $job) {
         while ($job->isRunning()) {
             sleep(1);
             // sleep is interrupted by signal
             $this->processManager->dispatchSignals();
         }
     }
 }
示例#3
0
 public function stop(ProcessManager $processManager)
 {
     if ($this->isRunning()) {
         $processManager->kill($this->pid);
     }
 }