public function __construct($path, $args = NULL)
 {
     $this->path = \Tester\Helpers::escapeArg($path);
     $proc = proc_open("{$this->path} -n {$args} -v", array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE));
     $output = stream_get_contents($pipes[1]);
     $this->error = trim(stream_get_contents($pipes[2]));
     if (proc_close($proc)) {
         throw new \Exception("Unable to run '{$path}': " . preg_replace('#[\\r\\n ]+#', ' ', $this->error));
     } elseif (!preg_match('#^PHP (\\S+).*c(g|l)i#i', $output, $matches)) {
         throw new \Exception("Unable to detect PHP version (output: {$output}).");
     }
     $this->version = $matches[1];
     $this->cgi = strcasecmp($matches[2], 'g') === 0;
     $this->arguments = $args;
     $job = new Job(__DIR__ . '/info.php', $this, array('xdebug'));
     $job->run();
     $this->xdebug = !$job->getExitCode();
 }
Esempio n. 2
0
 function do_get_testchainedphp_hello_v1($job, $resp)
 {
     $content = json_encode("Hello from job");
     // do internal hello1 which just appends it name to our content
     $j = new Job($job);
     $j->name("do_get_internalphp_hello1_v1");
     $j->type(Job::JOB_SYNC);
     $j->content($content);
     $r = $j->run();
     // create sync http rest job back to localhost which takes
     // the output from previous job and adds its own name.
     $j = $this->job_manager()->job(HttpClient::METHOD_POST, $job->base_uri() . "/hello2");
     $j->content($r->content());
     $j->headers($r->headers());
     $r = $j->run();
     $resp->content($r->content());
     $resp->headers($r->headers());
     return Worker::WORKER_SUCCESS;
 }
Esempio n. 3
0
 /**
  * @param Job $job
  * @param BufferingStatsdDataFactory $stats
  * @param float $popTime
  * @return array Map of status/error/timeMs
  */
 private function executeJob(Job $job, $stats, $popTime)
 {
     $jType = $job->getType();
     $msg = $job->toString() . " STARTING";
     $this->logger->debug($msg);
     $this->debugCallback($msg);
     // Run the job...
     $rssStart = $this->getMaxRssKb();
     $jobStartTime = microtime(true);
     try {
         $status = $job->run();
         $error = $job->getLastError();
         $this->commitMasterChanges($job);
         DeferredUpdates::doUpdates();
         $this->commitMasterChanges($job);
     } catch (Exception $e) {
         MWExceptionHandler::rollbackMasterChangesAndLog($e);
         $status = false;
         $error = get_class($e) . ': ' . $e->getMessage();
         MWExceptionHandler::logException($e);
     }
     // Commit all outstanding connections that are in a transaction
     // to get a fresh repeatable read snapshot on every connection.
     // Note that jobs are still responsible for handling slave lag.
     wfGetLBFactory()->commitAll(__METHOD__);
     // Clear out title cache data from prior snapshots
     LinkCache::singleton()->clear();
     $timeMs = intval((microtime(true) - $jobStartTime) * 1000);
     $rssEnd = $this->getMaxRssKb();
     // Record how long jobs wait before getting popped
     $readyTs = $job->getReadyTimestamp();
     if ($readyTs) {
         $pickupDelay = max(0, $popTime - $readyTs);
         $stats->timing('jobqueue.pickup_delay.all', 1000 * $pickupDelay);
         $stats->timing("jobqueue.pickup_delay.{$jType}", 1000 * $pickupDelay);
     }
     // Record root job age for jobs being run
     $root = $job->getRootJobParams();
     if ($root['rootJobTimestamp']) {
         $age = max(0, $popTime - wfTimestamp(TS_UNIX, $root['rootJobTimestamp']));
         $stats->timing("jobqueue.pickup_root_age.{$jType}", 1000 * $age);
     }
     // Track the execution time for jobs
     $stats->timing("jobqueue.run.{$jType}", $timeMs);
     // Track RSS increases for jobs (in case of memory leaks)
     if ($rssStart && $rssEnd) {
         $stats->increment("jobqueue.rss_delta.{$jType}", $rssEnd - $rssStart);
     }
     if ($status === false) {
         $msg = $job->toString() . " t={$timeMs} error={$error}";
         $this->logger->error($msg);
         $this->debugCallback($msg);
     } else {
         $msg = $job->toString() . " t={$timeMs} good";
         $this->logger->info($msg);
         $this->debugCallback($msg);
     }
     return array('status' => $status, 'error' => $error, 'timeMs' => $timeMs);
 }
Esempio n. 4
0
 function push(Job $job)
 {
     $job->run();
 }