Resque\Host::cleanup PHP Method

cleanup() public method

Cleans up any dead hosts
public cleanup ( ) : array
return array List of cleaned hosts
    public function cleanup()
    {
        $hosts = $this->redis->smembers(self::redisKey());
        $workers = $this->redis->smembers(Worker::redisKey());
        $cleaned = array('hosts' => array(), 'workers' => array());
        foreach ($hosts as $hostname) {
            $host = new static($hostname);
            if (!$this->redis->exists(self::redisKey($host))) {
                $this->redis->srem(self::redisKey(), (string) $host);
                $cleaned['hosts'][] = (string) $host;
            } else {
                $host_workers = $this->redis->smembers(self::redisKey($host));
                foreach ($host_workers as $host_worker) {
                    if (!in_array($host_worker, $workers)) {
                        $cleaned['workers'][] = $host_worker;
                        $this->redis->srem(self::redisKey($host), $host_worker);
                    }
                }
            }
        }
        return $cleaned;
    }

Usage Example

Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $host = new Resque\Host();
     $cleaned_hosts = $host->cleanup();
     $worker = new Resque\Worker('*');
     $cleaned_workers = $worker->cleanup();
     $cleaned_hosts = array_merge_recursive($cleaned_hosts, $host->cleanup());
     $cleaned_jobs = Resque\Job::cleanup();
     $this->log('Cleaned hosts: <pop>' . json_encode($cleaned_hosts['hosts']) . '</pop>');
     $this->log('Cleaned workers: <pop>' . json_encode(array_merge($cleaned_hosts['workers'], $cleaned_workers)) . '</pop>');
     $this->log('Cleaned <pop>' . $cleaned_jobs['zombie'] . '</pop> zombie job' . ($cleaned_jobs['zombie'] == 1 ? '' : 's'));
     $this->log('Cleared <pop>' . $cleaned_jobs['processed'] . '</pop> processed job' . ($cleaned_jobs['processed'] == 1 ? '' : 's'));
 }
All Usage Examples Of Resque\Host::cleanup