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); }
/** * @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(); } } }
public function stop(ProcessManager $processManager) { if ($this->isRunning()) { $processManager->kill($this->pid); } }