public function compute(JobInterface $job) { if (!$job instanceof ImageJob) { throw new RuntimeException('Image worker only process image job'); } // throws a RuntimeException in case a parameter is missing $job->isOk(true); $parameters = $job->getParameters(); $tmpFile = $this->filesystem->createEmptyFile(sys_get_temp_dir(), null, null, $parameters['format'], 50); $this->alchemyst->open($job->getSource())->turnInto($tmpFile, $this->specificationsFromJob($job))->close(); return new Result(Result::TYPE_PATHFILE, $tmpFile); }
/** * {@inheritdoc} */ public function send(JobInterface $job) { $this->socket->send($job->toJson()); $response = $this->socket->recv(); try { $acknowledgement = AcknowledgementFactory::fromJson($response); } catch (RuntimeException $e) { throw new ClientRequestException('Message was not understood by gloubster server', $response); } if (!$acknowledgement instanceof JobAcknowledgement) { throw new ClientNotAcknowledgedRequestException('Message was not acknowledge by gloubster server', $response, $acknowledgement); } return $acknowledgement; }
/** * {@inheritdoc} */ public function acknowledge(JobInterface $job) { if (!$this->client) { $this->initClient(); } $data = $job->toJson(); try { $request = $this->client->post($this->url, array('Content-Type' => 'application/json'), $this->useBody ? $data : null); if ($this->parameter) { $request->setPostField($this->parameter, $data); } $request->send(); } catch (GuzzleException $e) { throw new RuntimeException('A guzzle exception has been raised', $e->getCode(), $e); } catch (\Exception $e) { throw new RuntimeException('A unexpected exception has been raised', $e->getCode(), $e); } return $this; }
public function hashJob(JobInterface $job) { $hash = array(); foreach (json_decode($job->toJson(), true) as $key => $value) { if (is_array($value)) { $value = json_encode($value); } $hash[] = $key; $hash[] = $value; } return $hash; }
public function acknowledge(JobInterface $job) { file_put_contents($this->path, $job->toJson()); }
private function log(JobInterface $message) { $this->channel->basic_publish(new AMQPMessage($message->toJson()), Configuration::EXCHANGE_DISPATCHER, Configuration::ROUTINGKEY_LOG); }