UrbanIndo\Yii2\Queue\Queue::post PHP Méthode

post() public méthode

Post new job to the queue. This will trigger event EVENT_BEFORE_POST and EVENT_AFTER_POST.
public post ( UrbanIndo\Yii2\Queue\Job &$job ) : boolean
$job UrbanIndo\Yii2\Queue\Job The job.
Résultat boolean Whether operation succeed.
    public function post(Job &$job)
    {
        $this->trigger(self::EVENT_BEFORE_POST, $beforeEvent = new Event(['job' => $job]));
        if (!$beforeEvent->isValid) {
            return false;
        }
        $return = $this->postJob($job);
        if (!$return) {
            return false;
        }
        $this->trigger(self::EVENT_AFTER_POST, new Event(['job' => $job]));
        return true;
    }

Usage Example

Exemple #1
0
 /**
  * Endpoint to post a job to queue.
  * @return mixed
  * @throws \yii\web\ServerErrorHttpException When failed to post.
  */
 public function actionPost()
 {
     $job = $this->createJobFromRequest();
     /* @var $queue \UrbanIndo\Yii2\Queue\Queue */
     if ($this->queue->post($job)) {
         return ['status' => 'okay', 'jobId' => $job->id];
     } else {
         throw new \yii\web\ServerErrorHttpException('Failed to post job');
     }
 }
All Usage Examples Of UrbanIndo\Yii2\Queue\Queue::post