This method parses the specified route and creates the corresponding child module(s), controller and action
instances. It then calls [[Controller::runAction()]] to run the action with the given parameters.
If the route is empty, the method will use [[defaultRoute]].
/** * Run the job. * * @param Job $job */ public function run(Job $job) { \Yii::info('Running job', 'yii2queue'); try { if ($job->isCallable()) { $retval = $job->runCallable(); } else { $retval = $this->module->runAction($job->route, $job->data); } } catch (\Exception $e) { if ($job->isCallable()) { if (isset($job->header['signature']) && isset($job->header['signature']['route'])) { $id = $job->id . " " . \yii\helpers\Json::encode($job->header['signature']['route']); } else { $id = $job->id . ' callable'; } } else { $id = $job->route; } \Yii::error("Fatal Error: Error running route '{$id}'. Message: {$e->getMessage()}", 'yii2queue'); throw new \yii\base\Exception("Error running route '{$id}'. Message: {$e->getMessage()}. File: {$e->getFile()}[{$e->getLine()}]. Stack Trace: {$e->getTraceAsString()}", 500); } if ($retval !== false) { \Yii::info('Deleting job', 'yii2queue'); $this->delete($job); } }
/** * Run the job. * * @param Job $job */ public function run(Job $job) { \Yii::info('Running job', 'yii2queue'); try { if ($job->isCallable()) { $retval = $job->runCallable(); } else { $retval = $this->module->runAction($job->route, $job->data); } } catch (\Exception $e) { $route = $this->serialize($job); \Yii::error("Fatal Error: Error running route {$route}. Message: {$e->getMessage()}", 'yii2queue'); throw new \yii\base\Exception("Error running route {$route}. Message: {$e->getMessage()}. File: {$e->getFile()}[{$e->getLine()}]. Stack Trace: {$e->getTraceAsString()}", 500); } if ($retval !== false) { \Yii::info('Deleting job', 'yii2queue'); $this->delete($job); } }
/** * Runs a request specified in terms of a route. * The route can be either an ID of an action within this controller or a complete route consisting * of module IDs, controller ID and action ID. If the route starts with a slash '/', the parsing of * the route will start from the application; otherwise, it will start from the parent module of this controller. * @param string $route the route to be handled, e.g., 'view', 'comment/view', '/admin/comment/view'. * @param array $params the parameters to be passed to the action. * @return mixed the result of the action. * @see runAction() */ public function run($route, $params = []) { $pos = strpos($route, '/'); if ($pos === false) { return $this->runAction($route, $params); } elseif ($pos > 0) { return $this->module->runAction($route, $params); } return Yii::$app->runAction(ltrim($route, '/'), $params); }
/** * Run the job. * * @param Job $job The job to be executed. * * @return void * @throws \yii\base\Exception Exception. */ public function run(Job $job) { $this->trigger(self::EVENT_BEFORE_RUN, $beforeEvent = new Event(['job' => $job])); if (!$beforeEvent->isValid) { return; } \Yii::info('Running job', 'yii2queue'); try { if ($job->isCallable()) { $retval = $job->runCallable(); } else { $retval = $this->module->runAction($job->route, $job->data); } } catch (\Exception $e) { if ($job->isCallable()) { if (isset($job->header['signature']) && isset($job->header['signature']['route'])) { $id = $job->id . ' ' . \yii\helpers\Json::encode($job->header['signature']['route']); } else { $id = $job->id . ' callable'; } } else { $id = $job->route; } \Yii::error("Fatal Error: Error running route '{$id}'. Message: {$e->getMessage()}", 'yii2queue'); if ($this->releaseOnFailure) { $this->release($job); } throw new \yii\base\Exception("Error running route '{$id}'. " . "Message: {$e->getMessage()}. " . "File: {$e->getFile()}[{$e->getLine()}]. Stack Trace: {$e->getTraceAsString()}", 500); } $this->trigger(self::EVENT_AFTER_RUN, new Event(['job' => $job, 'returnValue' => $retval])); if ($retval !== false) { \Yii::info('Deleting job', 'yii2queue'); $this->delete($job); } else { if ($this->releaseOnFailure) { $this->release($job); } } }