/** * Notify the Client * * @param int $type one of NOTIFY_* * @param string $data * @return bool */ public function notify($type, $data = null) { if ($type == JobInterface::NOTIFY_COMPLETE) { return $this->job->sendComplete($data); } if ($type == JobInterface::NOTIFY_DATA) { return $this->job->sendData($data); } if ($type == JobInterface::NOTIFY_EXCEPTION) { return $this->job->sendException($data); } if ($type == JobInterface::NOTIFY_FAIL) { return $this->job->sendFail(); } if ($type == JobInterface::NOTIFY_WARNING) { return $this->job->notifyWarning($data); } return false; }
/** * Executes a [Request] object and returns the response * * // Create a request * $request = Request::factory('/users/load/1'); * * // Execute the request * $response = Request_Async_Gearman::execute_request($request); * * Used as a callback by Request_Async_Gearman to handle the request * processing. * * @param Kohana_Request request to process * @return Kohana_Response the response from the request */ public static function execute_request(GearmanJob $job) { // Unserialise the request $request = unserialize($job->workload()); // Send starting status $job->sendStatus(1, 2); // Encapsulate request execution try { // Get the response $response = $request->execute()->headers('X-Request-Uri', $request->uri()); } catch (Exception $e) { // Send the exception to Gearman $job->sendException($e->getMessage()); return; } // Send complete status $job->sendStatus(2, 2); // Send the response $job->sendData(serialize($response)); }