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; }
/** * 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'); } }