Ejemplo n.º 1
0
 /**
  * Run cron(s) in multiple domains
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     $type = $request->getParam('type');
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException(sprintf('%s can only be used from a console.', __METHOD__));
     }
     $phpSelf = realpath(static::PHP_SELF);
     if (empty($phpSelf) || !is_file($phpSelf)) {
         throw new \RuntimeException(sprintf('%s: php not found at "%s" (in "%s").', __METHOD__, static::PHP_SELF, getcwd()));
     }
     $result = 'Running ' . $type . ' cron(s) ...' . PHP_EOL . PHP_EOL;
     foreach ($this->mimicSiteInfos() as $siteInfo) {
         $domain = $siteInfo->getDomain();
         $process = new Process(array('command' => 'php', 'arguments' => array($phpSelf, 'cron', $domain, $type), 'environmentVariables' => array('GRIDGUYZ_HOST' => $domain, 'HTTP_HOST' => $domain)));
         $result .= 'Calling process ...' . PHP_EOL . $process->getRunCommand() . PHP_EOL;
         $output = tempnam('./data/', $domain);
         $descr = array(Process::TYPE_FILE, $output, Process::MODE_APPEND);
         file_put_contents($output, '');
         $process->open(array(Process::STREAM_STDOUT => $descr, Process::STREAM_STDERR => $descr));
         $return = $process->close();
         $messages = rtrim(file_get_contents($output), PHP_EOL);
         unlink($output);
         if ($messages) {
             $result .= static::PADDING . preg_replace('/[' . PHP_EOL . ']+/', '$0' . static::PADDING, $messages) . PHP_EOL;
         }
         $result .= sprintf('Process returned with #%d: %s' . PHP_EOL . PHP_EOL, $return, $return ? 'error!' : 'success.');
     }
     $result .= 'Done.' . PHP_EOL;
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Test open() & close() & related functionaily
  */
 public function testOpenAndClose()
 {
     $process = new Process(array('command' => $cmd = 'test_command', 'openCallback' => $this->getCallback('open'), 'closeCallback' => $this->getCallback('close'), 'validationCallback' => $this->getCallback('validate'), 'arguments' => $args = array('arg_1', 'arg_2'), 'workingDirectory' => __DIR__, 'environmentVariables' => $envs = array('env_1' => 'val 1', 'env_2' => 'val 2'), 'mergeEnvironmentVariables' => false, 'options' => $opts = array('opt_1' => 'val 1', 'opt_2' => 'val 2')));
     $descriptors = array();
     $this->callbacks->expects($this->any())->method('validate')->will($this->returnCallback(function ($pid) {
         return $pid == 'pid';
     }));
     $this->callbacks->expects($this->once())->method('open')->with(escapeshellcmd($cmd) . ' ' . implode(' ', array_map('escapeshellarg', $args)), $descriptors, array(), __DIR__, $envs, $opts)->will($this->returnValue('pid'));
     $this->callbacks->expects($this->once())->method('close')->with('pid')->will($this->returnValue(true));
     $process->run();
 }