Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/step/HarbormasterSleepBuildStepImplementation.php
12256 views
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
15
public function getBuildStepGroupKey() {
16
return HarbormasterTestBuildStepGroup::GROUPKEY;
17
}
18
19
public function getDescription() {
20
return pht(
21
'Sleep for %s seconds.',
22
$this->formatSettingForDescription('seconds'));
23
}
24
25
public function execute(
26
HarbormasterBuild $build,
27
HarbormasterBuildTarget $build_target) {
28
29
$settings = $this->getSettings();
30
31
$target = time() + $settings['seconds'];
32
33
// Use $build_update so that we only reload every 5 seconds, but
34
// the sleep mechanism remains accurate.
35
$build_update = 5;
36
37
while (time() < $target) {
38
sleep(1);
39
40
if ($build_update <= 0) {
41
$build->reload();
42
$build_update = 5;
43
44
if ($this->shouldAbort($build, $build_target)) {
45
throw new HarbormasterBuildAbortedException();
46
}
47
} else {
48
$build_update -= 1;
49
}
50
}
51
}
52
53
public function getFieldSpecifications() {
54
return array(
55
'seconds' => array(
56
'name' => pht('Seconds'),
57
'type' => 'int',
58
'required' => true,
59
'caption' => pht('The number of seconds to sleep for.'),
60
),
61
);
62
}
63
64
}
65
66