Beispiel #1
0
 public function unserialize(\Pheanstalk\Job $pheanstalkJob)
 {
     $data = json_decode($pheanstalkJob->getData());
     $data->data = (array) $data->data;
     $data->data['_beanstalk_id'] = $pheanstalkJob->getId();
     return new Job($data->name, $data->data);
 }
Beispiel #2
0
 /**
  * Esegue il messaggio uscito dal tubo
  *
  * @param string $message
  * @return mixed
  */
 public static function resolve(Job $job, LoggerInterface $logger = null)
 {
     $message = $job->getData();
     $data = self::decode($message);
     $time = @$data[self::TIME_KEY];
     $action = @$data[self::ACTION_KEY];
     if (empty($action)) {
         throw new \Exception("Nessuna azione trovata nel messaggio!");
     }
     $className = self::QUEUEJOBS_NAMESPACE . '\\' . $action;
     if (!class_exists($className)) {
         throw new \Exception("Nessuna classe trovata associata all'azione {$action}!");
     }
     $queueJob = new $className($job);
     if (!$queueJob instanceof QueueJobInterface) {
         throw new \Exception("la classe dell'azione {$action} non soddisfa il contratto!");
     }
     $params = @$data[self::PARAMS_KEY];
     $params = !empty($params) ? $params : [];
     //passo i parametri al QueueJob
     $queueJob->setParameters($params);
     $queueJob->setPushedTime(Carbon::parse($time));
     //esecuzione
     return $queueJob->run();
 }
Beispiel #3
0
 /**
  * Scrive un log del job se possibile
  *
  * @param int $jobId
  * @param string $message
  * @return null
  */
 private function log(Job $job, $message, $severity = LoggerInterface::SEVERITY_INFO)
 {
     if (!empty($this->logger)) {
         $jobId = $job->getId();
         $timeString = date('Y-m-d H:i:s');
         $msg = "[{$timeString} QueueJob: {$jobId}] {$message}";
         $this->logger->log($msg, $severity);
     }
 }
 /**
  * @param Job $job
  * @return int
  * @throws \Exception
  */
 protected function processJob(Job $job)
 {
     $data = json_decode($job->getData(), true);
     // Throw exception
     if ('error' === $data['message']) {
         throw new \Exception('Example error thrown from worker');
     }
     $this->output->writeln('<comment>' . $data['message'] . '</comment>');
     return self::ACTION_DELETE;
 }
 public function testExecute()
 {
     $args = $this->getCommandArgs();
     $job = new Job($args['job'], 'data');
     $this->pheanstalk->expects($this->once())->method('peek')->with($job->getId())->will($this->returnValue($job));
     $command = $this->application->find('leezy:pheanstalk:peek');
     $commandTester = new CommandTester($command);
     $commandTester->execute($args);
     $this->assertContains(sprintf('Job id: %d', $job->getId()), $commandTester->getDisplay());
     $this->assertContains(sprintf('Data: %s', $job->getData()), $commandTester->getDisplay());
 }
Beispiel #6
0
 public function __call($method, $args)
 {
     try {
         $result = call_user_func_array(array($this->_beanstalk, $method), $args);
         //Chaining.
         if ($result instanceof Pheanstalk) {
             return $this;
         }
         //Check for json data.
         if ($result instanceof Job) {
             if ($this->isJson($result->getData())) {
                 $result = new Job($result->getId(), json_decode($result->getData()));
             }
         }
         return $result;
     } catch (ConnectionException $e) {
         Yii::error($e);
         return false;
     }
 }
 /**
  * @param Job $job
  * @return int
  * @throws \Exception
  */
 protected function processJob(Job $job)
 {
     $data = json_decode($job->getData());
     $em = $this->container->get('doctrine.orm.entity_manager');
     // Get the File
     $file = new \SplFileInfo($data->file_path);
     // Check if we have a filename to use
     $fileName = isset($data->file_name) ? $data->file_name : null;
     // Upload the File to S3
     $photoUrl = $this->container->get('service_photo_upload')->uploadPhoto($file, $data->content_type, $fileName);
     // Get the Profile entity
     $profile = $em->find('AppBundle:Profile', $data->profile_id);
     // Update Profile
     $profile->setPhoto($photoUrl);
     $profile->setPhotoUploading(false);
     // Flush
     $em->flush($profile);
     $em->clear();
     $this->output->writeln('<comment>Profile Photo Uploaded</comment>');
     return self::ACTION_DELETE;
 }
Beispiel #8
0
 /**
  * Get the job identifier.
  *
  * @return string
  */
 public function getJobId()
 {
     return $this->job->getId();
 }
 /**
  * Take a job, its stats and add it to the
  * destination beanstalk instance.
  *
  * @param Pheanstalk\Job $job   job to process
  * @param array          $stats Stats about the job
  *
  * @return void
  */
 protected function addToDest(Job $job, ArrayResponse $stats)
 {
     // add the job to the destination server
     $this->destination->putInTube($stats->tube, $job->getData(), $stats->pri, $stats->{'time-left'}, $stats->ttr);
 }
Beispiel #10
0
 /**
  * Creates a new BeanstalkdManager
  *
  * @param string              $queue
  * @param PheanstalkJob      $job
  * @param BeanstalkdConnector $connector
  */
 public function __construct($queue, PheanstalkJob $job, BeanstalkdConnector $connector)
 {
     $this->pheanstalkJob = $job;
     $this->payload = json_decode($job->getData(), true);
     parent::__construct($queue, $connector);
 }
Beispiel #11
0
 public function __construct($id, $data, JobControlInterface $queue)
 {
     $this->queue = $queue;
     $this->jobData = is_array($data) ? new ArrayCollection($data) : $data;
     parent::__construct($id, $this->jobData);
 }
Beispiel #12
0
 protected function createJob(Pheanstalk\Job $job)
 {
     try {
         $data = $this->serializer->unserialize($job->getData());
         $job = new Job($job->getId(), $data, $this);
     } catch (NotSerializableException $e) {
         $job = new UnserializableJob($job->getId(), $job->getData(), $this, $e);
     }
     $this->logProcessor->setCurrentJob($job);
     return $job;
 }
Beispiel #13
0
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     return $this->serializer->unserialize($this->job->getData());
 }