/** * Unregister this worker in Redis */ public function unregister() { if ($this->child === 0) { // This is a child process so don't unregister worker // However if the shutdown was due to an error, for instance the job hitting the // max execution time, then catch the error and fail the job if ($error = error_get_last() and in_array($error['type'], $this->shutdownErrors)) { $this->job->fail(new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line'])); } return; } elseif (!is_null($this->child)) { // There is a child process running $this->log('There is a child process pid:' . $this->child . ' running, killing it', Logger::DEBUG); $this->killChild(); } if (is_object($this->job)) { $this->job->fail(new Exception\Cancel()); $this->log('Failing running job <pop>' . $this->job . '</pop>', Logger::NOTICE); } $this->log('Unregistering worker <pop>' . $this . '</pop>', Logger::NOTICE); $this->redis->srem(self::redisKey(), $this->id); $this->redis->expire(self::redisKey($this), \Resque::getConfig('default.expiry_time', \Resque::DEFAULT_EXPIRY_TIME)); $this->host->finished($this); // Remove pid file if one set if (!is_null($this->pidFile) and getmypid() === (int) trim(file_get_contents($this->pidFile))) { unlink($this->pidFile); } Event::fire(Event::WORKER_UNREGISTER, $this); }