Esempio n. 1
0
 protected function processQuery(\GearmanJob $job, Query $query)
 {
     $start = microtime(true);
     $job->sendStatus(0, 100);
     $tempfile = tempnam(sys_get_temp_dir(), 'transmute_image');
     $tempdest = tempnam(sys_get_temp_dir(), 'transmute_image');
     if (false === ($filecontent = @file_get_contents($query->getFile()))) {
         $this->logger->addInfo(sprintf('Unable to download file `%s`', $query->getFile()));
         return new Result($job->handle(), $query->getUuid(), $job->workload(), null, $this->workerName, $start, microtime(true), array(), array(sprintf('Unable to download file `%s`', $query->getFile())));
     }
     $this->logger->addInfo(sprintf('file %s retrieved', $query->getFile()));
     $job->sendStatus(30, 100);
     file_put_contents($tempfile, $filecontent);
     unset($filecontent);
     $job->sendStatus(50, 100);
     $specification = new Image();
     $width = $height = null;
     foreach ($query->getParameters() as $name => $value) {
         switch ($name) {
             case 'width':
                 $width = $value;
                 break;
             case 'height':
                 $height = $value;
                 break;
             case 'quality':
                 $specification->setQuality($value);
                 break;
         }
     }
     if (null !== $width && null !== $height) {
         $specification->setDimensions($width, $height);
     }
     try {
         $this->alchemyst->open($tempfile)->turnInto($tempdest, $specification)->close();
     } catch (Exception $e) {
         $this->logger->addInfo(sprintf('A media-alchemyst exception occured %s', $e->getMessage()));
         return new Result($job->handle(), $query->getUuid(), $job->workload(), null, $this->workerName, $start, microtime(true), array(), array(sprintf('A media-alchemyst exception occured %s', $e->getMessage())));
     } catch (\Exception $e) {
         $this->logger->addInfo(sprintf('An unexpected exception occured %s', $e->getMessage()));
         return new Result($job->handle(), $query->getUuid(), $job->workload(), null, $this->workerName, $start, microtime(true), array(), array(sprintf('An unexpected exception occured %s', $e->getMessage())));
     }
     $result = new Result($job->handle(), $query->getUuid(), $job->workload(), file_get_contents($tempdest), $this->workerName, $start, microtime(true));
     unlink($tempfile);
     unlink($tempdest);
     $this->logger->addInfo('Conversion successfull');
     $job->sendStatus(100, 100);
     return $result;
 }
 /**
  * Test method to run as a job
  *
  * @param \GearmanJob $job Object with job parameters
  *
  * @return boolean
  *
  * @Gearman\Job(
  *     defaultMethod = "doLowBackground"
  * )
  */
 public function testB(\GearmanJob $job)
 {
     $workload = $job->workload();
     echo "Received job: " . $job->handle() . "\n";
     echo "Workload: {$workload}\n";
     $result = strrev($workload);
     echo "Result: {$result}\n";
     return $result;
 }
Esempio n. 3
0
 public final function execute(\GearmanJob $job)
 {
     $this->logger->addInfo(sprintf('Receiving job handle %s (%s)', $job->handle(), $job->unique()));
     try {
         $query = unserialize($job->workload());
         $this->logger->addInfo('Workload unserialized');
         if (!$query instanceof Query) {
             throw new RuntimeException('Expecting a Gloubster Query');
         }
         $this->logger->addInfo('Query OK');
     } catch (RuntimeException $e) {
         $this->logger->addError(sprintf('Error while getting the job : %s', $e->getMessage()));
         return;
     }
     try {
         $query->getDelivery($this->deliveryFactory, $this->configuration)->deliver($query->getUuid(), $this->processQuery($job, $query));
     } catch (\Exception $e) {
         $this->logger->addError(sprintf('Error while processing : %s', $e->getMessage()));
     }
 }
 /**
  * @method setWorkJob
  * @access public
  *
  * Set current work job
  *
  * @param (GearmanJob) - Cuurent job
  *
  * @return (void)
  */
 public function setWorkJob(GearmanJob $job)
 {
     $this->_worker = $job;
     $this->getLogger()->info("Workjob start with jobhandle: " . $job->handle());
     echo "Workjob start with jobhandle: " . $job->handle() . "\n";
 }