public function getApplication()
 {
     if ($this->_application === null) {
         $app = [];
         foreach ($this->jobs as $name => $job) {
             $job = Yii::createComponent($job);
             if (!$job instanceof JobInterface) {
                 throw new \yii\base\InvalidConfigException('Gearman job must be instance of JobInterface.');
             }
             $job->setName($name);
             for ($i = 0; $i < $job->count; $i++) {
                 $this->_process = null;
                 $application = new Application($name . $i, $this->getConfig(), $this->getProcess($name . $i));
                 $application->add($job);
                 $app[] = $application;
             }
         }
         $this->_application = $app;
     }
     return $this->_application;
 }
Example #2
0
 /**
  * @param JobInterface $job
  * @param GearmanJob $gearmanJob
  * @param Application $root
  * @return mixed
  */
 public function executeJob(JobInterface $job, GearmanJob $gearmanJob, Application $root)
 {
     if ($root->getConfig()->getAutoUpdate() && !$root->isAllowingJob) {
         $root->restart();
         return null;
     }
     $root->isAllowingJob = false;
     if (null !== $root->logger) {
         $root->logger->info("Executing job {$job->getName()}");
     }
     return $job->execute($gearmanJob);
 }
 protected function runApplication(Application $app)
 {
     return $app->run((bool) $this->fork);
 }