[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class HarbormasterSleepBuildStepImplementation
   4    extends HarbormasterBuildStepImplementation {
   5  
   6    public function getName() {
   7      return pht('Sleep');
   8    }
   9  
  10    public function getGenericDescription() {
  11      return pht('Sleep for a specified number of seconds.');
  12    }
  13  
  14    public function getDescription() {
  15      return pht(
  16        'Sleep for %s seconds.',
  17        $this->formatSettingForDescription('seconds'));
  18    }
  19  
  20    public function execute(
  21      HarbormasterBuild $build,
  22      HarbormasterBuildTarget $build_target) {
  23  
  24      $settings = $this->getSettings();
  25  
  26      $target = time() + $settings['seconds'];
  27  
  28      // Use $build_update so that we only reload every 5 seconds, but
  29      // the sleep mechanism remains accurate.
  30      $build_update = 5;
  31  
  32      while (time() < $target) {
  33        sleep(1);
  34  
  35        if ($build_update <= 0) {
  36          $build->reload();
  37          $build_update = 5;
  38  
  39          if ($this->shouldAbort($build, $build_target)) {
  40            throw new HarbormasterBuildAbortedException();
  41          }
  42        } else {
  43          $build_update -= 1;
  44        }
  45      }
  46    }
  47  
  48    public function getFieldSpecifications() {
  49      return array(
  50        'seconds' => array(
  51          'name' => pht('Seconds'),
  52          'type' => 'int',
  53          'required' => true,
  54          'caption' => pht('The number of seconds to sleep for.'),
  55        ),
  56      );
  57    }
  58  
  59  }


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