/** * Start worker. * * @param WorkerInterface $worker The worker to start. * @return void */ public function startWorker(WorkerInterface $worker) { $parent = $this->system->createCurrentProcess(); $this->eventDispatcher->dispatch(ResqueEvents::PRE_FORK); $child = $parent->fork(); // This exists because workers that get reset after a crash still hold their old id. // @todo this shouldn't be needed if id was always derived.. hmm. $worker->setId(null); if (null === $child) { // This is spawned worker process, it will process jobs until told to exit. $this->eventDispatcher->dispatch(ResqueEvents::POST_FORK_CHILD); $worker->setProcess($this->system->createCurrentProcess()); $this->registry->register($worker); $worker->work(); $this->registry->deregister($worker); exit(0); } $this->eventDispatcher->dispatch(ResqueEvents::POST_FORK_PARENT); $worker->setProcess($child); $this->logger->info('Successfully started worker {worker} with pid {childPid}', array('worker' => $worker, 'childPid' => $child->getPid())); }