public function execute(HarbormasterBuild $build, HarbormasterBuildTarget $build_target)
 {
     $viewer = PhabricatorUser::getOmnipotentUser();
     $settings = $this->getSettings();
     $variables = $build_target->getVariables();
     $artifact = $build_target->loadArtifact($settings['hostartifact']);
     $impl = $artifact->getArtifactImplementation();
     $lease = $impl->loadArtifactLease($viewer);
     $this->platform = $lease->getAttribute('platform');
     $command = $this->mergeVariables(array($this, 'escapeCommand'), $settings['command'], $variables);
     $this->platform = null;
     $interface = $lease->getInterface('command');
     $future = $interface->getExecFuture('%C', $command);
     $log_stdout = $build->createLog($build_target, 'remote', 'stdout');
     $log_stderr = $build->createLog($build_target, 'remote', 'stderr');
     $start_stdout = $log_stdout->start();
     $start_stderr = $log_stderr->start();
     $build_update = 5;
     // Read the next amount of available output every second.
     $futures = new FutureIterator(array($future));
     foreach ($futures->setUpdateInterval(1) as $key => $future_iter) {
         if ($future_iter === null) {
             // Check to see if we should abort.
             if ($build_update <= 0) {
                 $build->reload();
                 if ($this->shouldAbort($build, $build_target)) {
                     $future->resolveKill();
                     throw new HarbormasterBuildAbortedException();
                 } else {
                     $build_update = 5;
                 }
             } else {
                 $build_update -= 1;
             }
             // Command is still executing.
             // Read more data as it is available.
             list($stdout, $stderr) = $future->read();
             $log_stdout->append($stdout);
             $log_stderr->append($stderr);
             $future->discardBuffers();
         } else {
             // Command execution is complete.
             // Get the return value so we can log that as well.
             list($err) = $future->resolve();
             // Retrieve the last few bits of information.
             list($stdout, $stderr) = $future->read();
             $log_stdout->append($stdout);
             $log_stderr->append($stderr);
             $future->discardBuffers();
             break;
         }
     }
     $log_stdout->finalize($start_stdout);
     $log_stderr->finalize($start_stderr);
     if ($err) {
         throw new HarbormasterBuildFailureException();
     }
 }
 public function execute(HarbormasterBuild $build, HarbormasterBuildTarget $build_target)
 {
     // We can only wait when building against commits.
     $buildable = $build->getBuildable();
     $object = $buildable->getBuildableObject();
     if (!$object instanceof PhabricatorRepositoryCommit) {
         return;
     }
     // Block until all previous builds of the same build plan have
     // finished.
     $plan = $build->getBuildPlan();
     $existing_logs = id(new HarbormasterBuildLogQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withBuildTargetPHIDs(array($build_target->getPHID()))->execute();
     if ($existing_logs) {
         $log = head($existing_logs);
     } else {
         $log = $build->createLog($build_target, 'waiting', 'blockers');
     }
     $blockers = $this->getBlockers($object, $plan, $build);
     if ($blockers) {
         $log->start();
         $log->append(pht("Blocked by: %s\n", implode(',', $blockers)));
         $log->finalize();
     }
     if ($blockers) {
         throw new PhabricatorWorkerYieldException(15);
     }
 }
 public function execute(HarbormasterBuild $build, HarbormasterBuildTarget $build_target)
 {
     $viewer = PhabricatorUser::getOmnipotentUser();
     $settings = $this->getSettings();
     $variables = $build_target->getVariables();
     $uri = $this->mergeVariables('vurisprintf', $settings['uri'], $variables);
     $log_body = $build->createLog($build_target, $uri, 'http-body');
     $start = $log_body->start();
     $method = nonempty(idx($settings, 'method'), 'POST');
     $future = id(new HTTPSFuture($uri))->setMethod($method)->setTimeout(60);
     $credential_phid = $this->getSetting('credential');
     if ($credential_phid) {
         $key = PassphrasePasswordKey::loadFromPHID($credential_phid, $viewer);
         $future->setHTTPBasicAuthCredentials($key->getUsernameEnvelope()->openEnvelope(), $key->getPasswordEnvelope());
     }
     list($status, $body, $headers) = $this->resolveFuture($build, $build_target, $future);
     $log_body->append($body);
     $log_body->finalize($start);
     if ($status->getStatusCode() != 200) {
         $build->setBuildStatus(HarbormasterBuild::STATUS_FAILED);
     }
 }