Пример #1
0
 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);
     }
     $parent = $app->run((bool) $this->fork);
     return $parent;
 }
Пример #2
0
 public function getApplication()
 {
     if ($this->_application === null) {
         $app = [];
         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);
             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;
 }
Пример #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);
 }