protected function runApplication(Application $app)
 {
     $fork = (bool) $this->fork;
     if ($fork) {
         $this->stdout("Success: Process is started\n", Console::FG_GREEN);
     } else {
         $this->stdout("Success: Process is started, but not daemonized\n", Console::FG_YELLOW);
     }
     $app->run((bool) $this->fork);
 }
 public function getApplication($id)
 {
     if ($this->_application === null) {
         $app = new Application($id, $this->getConfig(), $this->getProcess($id));
         foreach ($this->jobs as $name => $job) {
             $job = Yii::createObject($job);
             if (!$job instanceof JobInterface) {
                 throw new \yii\base\InvalidConfigException('Gearman job must be instance of JobInterface.');
             }
             $job->setName($name);
             $app->add($job);
         }
         $this->_application = $app;
     }
     return $this->_application;
 }
Example #3
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);
 }