Resque_Worker::all PHP Method

all() public static method

Return all workers known to Resque as instantiated instances.
public static all ( ) : array
return array
    public static function all()
    {
        $workers = Resque::redis()->smembers('workers');
        if (!is_array($workers)) {
            $workers = array();
        }
        $instances = array();
        foreach ($workers as $workerId) {
            $instances[] = self::find($workerId);
        }
        return $instances;
    }

Usage Example

Beispiel #1
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('');
 }
All Usage Examples Of Resque_Worker::all