public function testApplication() { $process = new Process($this->config); $application = new Application($this->config, $process); $application->add(new MockJob()); $application->run(); $test = $process->isRunning(); $this->assertTrue($test); $process->stop(); }
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); }
/** * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $output->write('Starting gearman-handler: '); if (!$this->isDaemon) { $isDaemon = $this->isDaemon; } elseif ($input->hasOption('daemon')) { $isDaemon = $input->getOption('daemon'); if ($isDaemon == 'false') { $isDaemon = false; } elseif ($isDaemon == 'true') { $isDaemon = true; } else { $isDaemon = (bool) $isDaemon; } } else { $isDaemon = $this->isDaemon; } $config = $this->getConfig(); $config->set($input->getOptions()); $process = $this->getProcess(); if ($process->isRunning()) { $output->write('[ <error>Failed: Process is already running</error> ]', true); return; } if (is_callable($this->getRuntime())) { $runtime = $this->getRuntime(); $this->setResult(true); $output->write('[ <fg=green>OK</fg=green> ]', true); $runtime(); } else { $app = $this->getGearmanApplication(); if (!$app instanceof GearmanApplication) { $app = new Application($this->getConfig(), $this->getProcess()); } $this->setResult(true); $output->write('[ <fg=green>OK</fg=green> ]', true); $app->run($isDaemon); } }
public function bootstrap($restart = false) { if ($this->getConfig()->getEnvVariables()) { $this->addEnvVariables(); } $bootstrap = $this->getConfig()->getBootstrap(); if (is_file($bootstrap)) { require_once $bootstrap; if ($restart && null !== self::$instance && spl_object_hash($this) !== spl_object_hash(self::$instance)) { self::$instance->unserialize($this->serialize()); self::$instance->run(false, true); $this->kill = true; } } $class = $this->getConfig()->getClass(); if (!empty($class)) { $bootstrap = new $class(); if (!$bootstrap instanceof BootstrapInterface) { throw new InvalidBootstrapClassException(); } $bootstrap->run($this); } $this->isBootstraped = true; }
if (isset($_SERVER['argv'][1])) { $serialized = $_SERVER['argv'][1]; if (is_file($serialized)) { $application = file_get_contents($serialized); if (!empty($application)) { $application = unserialize($application); } unlink($serialized); } if (!$application instanceof Application) { $application = new Application(); } $process = $application->getProcess(); unlink($process->getPidFile()); $process->release(); $int = 0; while ($int < 1000) { if (file_exists($process->getPidFile())) { usleep(1000); $int++; } elseif (file_exists($process->getLockFile())) { $process->release(); usleep(1000); $int++; } else { $int = 1000; } } $application->setProcess(new Process($application->getConfig(), $application->getLogger())); $application->run(false, true); }