/** * Handles the heartbeat response from the worker handler. */ private function handleHeartbeatResponse() { $state = $this->worker->getState(); if (Worker::BUSY == $state) { /** * We should only reply in the following cases: * - A heartbeat is about to expire. * - We have a result. */ return; } if (Worker::RESULT_AVAILABLE == $state) { // A result is available send it to the worker handler. $this->handleResult(); return; } if (in_array($state, array(Worker::READY, Worker::RESULT, Worker::REGISTER))) { // Update the state to ready and forget about the last job. $this->worker->cleanup(); // Request a new job $this->sendToWorkerHandler(new GetJobRequest()); return; } if (Worker::SHUTDOWN != $state) { // The worker did not request a shutdown, however all other states should be handled at this point. $this->getLogger()->error('Invalid worker state: ' . $this->worker->getState() . '.'); } // Worker is completely shutdown, because there is no open connection to the worker handler. $this->worker->setState(Worker::INVALID); }