[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/harbormaster/step/ -> HarbormasterWaitForPreviousBuildStepImplementation.php (source)

   1  <?php
   2  
   3  final class HarbormasterWaitForPreviousBuildStepImplementation
   4    extends HarbormasterBuildStepImplementation {
   5  
   6    public function getName() {
   7      return pht('Wait for Previous Commits to Build');
   8    }
   9  
  10    public function getGenericDescription() {
  11      return pht(
  12        'Wait for previous commits to finish building the current plan '.
  13        'before continuing.');
  14    }
  15  
  16    public function execute(
  17      HarbormasterBuild $build,
  18      HarbormasterBuildTarget $build_target) {
  19  
  20      // We can only wait when building against commits.
  21      $buildable = $build->getBuildable();
  22      $object = $buildable->getBuildableObject();
  23      if (!($object instanceof PhabricatorRepositoryCommit)) {
  24        return;
  25      }
  26  
  27      // Block until all previous builds of the same build plan have
  28      // finished.
  29      $plan = $build->getBuildPlan();
  30  
  31      $existing_logs = id(new HarbormasterBuildLogQuery())
  32        ->setViewer(PhabricatorUser::getOmnipotentUser())
  33        ->withBuildTargetPHIDs(array($build_target->getPHID()))
  34        ->execute();
  35  
  36      if ($existing_logs) {
  37        $log = head($existing_logs);
  38      } else {
  39        $log = $build->createLog($build_target, 'waiting', 'blockers');
  40      }
  41  
  42      $blockers = $this->getBlockers($object, $plan, $build);
  43      if ($blockers) {
  44        $log->start();
  45        $log->append("Blocked by: ".implode(',', $blockers)."\n");
  46        $log->finalize();
  47      }
  48  
  49      if ($blockers) {
  50        throw new PhabricatorWorkerYieldException(15);
  51      }
  52    }
  53  
  54    private function getBlockers(
  55      PhabricatorRepositoryCommit $commit,
  56      HarbormasterBuildPlan $plan,
  57      HarbormasterBuild $source) {
  58  
  59      $call = new ConduitCall(
  60        'diffusion.commitparentsquery',
  61        array(
  62          'commit'   => $commit->getCommitIdentifier(),
  63          'callsign' => $commit->getRepository()->getCallsign(),
  64        ));
  65      $call->setUser(PhabricatorUser::getOmnipotentUser());
  66      $parents = $call->execute();
  67  
  68      $parents = id(new DiffusionCommitQuery())
  69        ->setViewer(PhabricatorUser::getOmnipotentUser())
  70        ->withRepository($commit->getRepository())
  71        ->withIdentifiers($parents)
  72        ->execute();
  73  
  74      $blockers = array();
  75  
  76      $build_objects = array();
  77      foreach ($parents as $parent) {
  78        if (!$parent->isImported()) {
  79          $blockers[] = pht('Commit %s', $parent->getCommitIdentifier());
  80        } else {
  81          $build_objects[] = $parent->getPHID();
  82        }
  83      }
  84  
  85      if ($build_objects) {
  86        $buildables = id(new HarbormasterBuildableQuery())
  87          ->setViewer(PhabricatorUser::getOmnipotentUser())
  88          ->withBuildablePHIDs($build_objects)
  89          ->withManualBuildables(false)
  90          ->execute();
  91        $buildable_phids = mpull($buildables, 'getPHID');
  92  
  93        if ($buildable_phids) {
  94          $builds = id(new HarbormasterBuildQuery())
  95            ->setViewer(PhabricatorUser::getOmnipotentUser())
  96            ->withBuildablePHIDs($buildable_phids)
  97            ->withBuildPlanPHIDs(array($plan->getPHID()))
  98            ->execute();
  99  
 100          foreach ($builds as $build) {
 101            if (!$build->isComplete()) {
 102              $blockers[] = pht('Build %d', $build->getID());
 103            }
 104          }
 105        }
 106      }
 107  
 108      return $blockers;
 109    }
 110  
 111  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1