Esempio n. 1
0
 /**
  * Run specific job script
  *
  * @param string
  */
 public function run($jobScript)
 {
     $this->jobStarted($jobScript);
     // -----
     $phpBin = 'php';
     $proc = proc_open($phpBin . ' ' . escapeshellarg($jobScript), array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, dirname($jobScript), NULL, array('bypass_shell' => TRUE));
     list($stdin, $stdout, $stderr) = $pipes;
     fclose($stdin);
     do {
         $status = proc_get_status($proc);
     } while ($status['running']);
     // -----
     $result = $status['exitcode'] == 0;
     if ($result) {
         $this->jobFinished($jobScript, $stdout, $stderr);
     } else {
         $this->jobFailed($jobScript, $stdout, $stderr);
     }
     fclose($stdout);
     fclose($stderr);
     proc_close($proc);
     /// @todo error handling
     if ($result) {
         unlink($jobScript);
     } else {
         $dir = $this->storage->directory . '/failed';
         FileSystem::createDirIfNotExists($dir);
         rename($jobScript, $dir . '/' . basename($jobScript));
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Creates new job with code and metadata
  *
  * @param string name
  * @param array metadata
  * @param string php code
  * @return string|FALSE absolute path to job file or FALSE on failure
  */
 public function createJob($name, array $metadata, $phpCode)
 {
     FileSystem::createDirIfNotExists($this->dir);
     $path = $this->dir . '/' . self::FILENAME_PREFIX . $name . '.' . md5($phpCode) . self::FILENAME_SUFFIX;
     $result = $this->getFileStorage()->write($path, $metadata, "<?php\n" . $phpCode);
     return $result === FALSE ? FALSE : $path;
 }