find() public static méthode

Given a worker ID, find it and return an instantiated worker class for it.
public static find ( string $workerId ) : Resque_Worker
$workerId string The ID of the worker.
Résultat Resque_Worker Instance of the worker. False if the worker does not exist.
Exemple #1
0
 public function testGetWorkerById()
 {
     $worker = new Resque_Worker('*');
     $worker->registerWorker();
     $newWorker = Resque_Worker::find((string) $worker);
     $this->assertEquals((string) $worker, (string) $newWorker);
 }
Exemple #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('all')) {
         $workers = \Resque_Worker::all();
     } else {
         $worker = \Resque_Worker::find($input->getArgument('id'));
         if (!$worker) {
             $availableWorkers = \Resque_Worker::all();
             if (!empty($availableWorkers)) {
                 throw new \RuntimeException('A running worker must be specified');
             }
         }
         $workers = $worker ? array($worker) : array();
     }
     if (count($workers) <= 0) {
         $output->writeln(array('No workers running', ''));
         return;
     }
     $signal = $input->getOption('force') ? SIGTERM : SIGQUIT;
     foreach ($workers as $worker) {
         $output->writeln(sprintf('%s %s...', $signal === SIGTERM ? 'Force stopping' : 'Stopping', $worker));
         list(, $pid) = explode(':', (string) $worker);
         posix_kill($pid, $signal);
     }
     $output->writeln('');
 }
Exemple #3
0
 public function getWorker($id)
 {
     $worker = \Resque_Worker::find($id);
     if (!$worker) {
         return null;
     }
     return new Worker($worker);
 }