Ejemplo n.º 1
0
 /**
  * @param Queue $queue Queue the job located.
  * @param Job   $job   Job to be executed.
  * @return array
  */
 protected function executeJob(Queue $queue, Job $job)
 {
     $start = time();
     $return = ['jobId' => $job->id, 'route' => $job->isCallable() ? 'callable' : $job->route, 'data' => $job->data, 'time' => date('Y-m-d H:i:s', $start)];
     try {
         ob_start();
         $queue->run($job);
         $output = ob_get_clean();
         $return2 = ['status' => 'success', 'level' => 'info'];
     } catch (\Exception $exc) {
         $output = ob_get_clean();
         Yii::$app->getResponse()->statusCode = 500;
         $return2 = ['status' => 'failed', 'level' => 'error', 'reason' => $exc->getMessage(), 'trace' => $exc->getTraceAsString()];
     }
     $return3 = ['stdout' => $output, 'duration' => time() - $start];
     return array_merge($return, $return2, $return3);
 }
Ejemplo n.º 2
0
 /**
  * Pack job so that it can be send.
  *
  * @param Job $job The job to serialize.
  * @return string JSON string.
  */
 protected function serialize(Job $job)
 {
     $return = [];
     if ($job->isCallable()) {
         $return['type'] = Job::TYPE_CALLABLE;
         $serializer = new \SuperClosure\Serializer();
         $return['route'] = $serializer->serialize($job->route);
     } else {
         $return['type'] = Job::TYPE_REGULAR;
         $return['route'] = $job->route;
     }
     $return['data'] = $job->data;
     return $this->serializeMessage($return);
 }