xaizek / fragile (License: AGPLv3+) (since 2018-12-07)
Simple lightweight CI, attempting to be somewhat Unix-like in its philosophy.
Commit 1d91d3d8dddbb724ce9ecd4bed9a7db1bac5d5a0

Read and write build start/end times
Author: xaizek
Author date (UTC): 2018-11-24 12:12
Committer name: xaizek
Committer date (UTC): 2018-11-24 12:40
Parent(s): 551c77ee56586a130266c225a9affa85b8d383a8
Signing key: 99DC5E4DB05F6BE2
Tree: e53ab0ffb459d1ef312f3962072756d59bf84555
File Lines added Lines deleted
classes/Build.php 47 9
classes/Builds.php 8 3
File classes/Build.php changed (mode: 100644) (index 2f846bd..7ccef81)
... ... class Build
30 30 * @param revision Revision of the associated buildset. * @param revision Revision of the associated buildset.
31 31 */ */
32 32 public function __construct($buildset, $buildername, $status, $exitcode, public function __construct($buildset, $buildername, $status, $exitcode,
33 $revision = null)
33 $revision = null, $starttime = 0, $endtime = 0)
34 34 { {
35 35 $this->buildset = $buildset; $this->buildset = $buildset;
36 36 $this->buildername = $buildername; $this->buildername = $buildername;
37 37 $this->status = $status; $this->status = $status;
38 38 $this->exitcode = $exitcode; $this->exitcode = $exitcode;
39 39 $this->revision = $revision; $this->revision = $revision;
40 $this->starttime = $starttime;
41 $this->endtime = $endtime;
40 42 } }
41 43
42 44 /** /**
 
... ... class Build
49 51 */ */
50 52 public static function get($buildset, $buildername) public static function get($buildset, $buildername)
51 53 { {
52 $sql = 'SELECT buildset, buildername, status, exitcode FROM builds '
54 $sql = 'SELECT buildset, buildername, status, exitcode, '
55 . ' starttime, endtime '
56 . 'FROM builds '
53 57 . 'WHERE buildset = ? AND buildername = ?'; . 'WHERE buildset = ? AND buildername = ?';
54 58 $statement = DB::prepare($sql); $statement = DB::prepare($sql);
55 59 if (!$statement if (!$statement
 
... ... class Build
61 65 return new Build($buildinfo['buildset'], return new Build($buildinfo['buildset'],
62 66 $buildinfo['buildername'], $buildinfo['buildername'],
63 67 $buildinfo['status'], $buildinfo['status'],
64 $buildinfo['exitcode']);
68 $buildinfo['exitcode'],
69 null,
70 $buildinfo['starttime'],
71 $buildinfo['endtime']);
65 72 } }
66 73
67 74 /** /**
 
... ... class Build
73 80 public static function create($buildset, $buildername) public static function create($buildset, $buildername)
74 81 { {
75 82 $sql = 'INSERT INTO ' $sql = 'INSERT INTO '
76 . 'builds(buildset, buildername, output, status, exitcode) '
77 . 'VALUES(?, ?, "", "pending", -1)';
83 . 'builds(buildset, buildername, output, status, exitcode, '
84 . ' starttime, endtime) '
85 . 'VALUES(?, ?, "", "pending", -1, 0, 0)';
78 86 $statement = DB::prepare($sql); $statement = DB::prepare($sql);
79 87 if (!$statement || $statement->execute([$buildset->buildsetid, if (!$statement || $statement->execute([$buildset->buildsetid,
80 88 $buildername]) === false) { $buildername]) === false) {
 
... ... class Build
115 123 */ */
116 124 public function markAsStarted() public function markAsStarted()
117 125 { {
118 $sql = 'UPDATE builds SET status = "running" '
126 $sql = 'UPDATE builds SET status = "running", starttime = ? '
119 127 . 'WHERE buildset = ? AND buildername = ?'; . 'WHERE buildset = ? AND buildername = ?';
120 128 $statement = DB::prepare($sql); $statement = DB::prepare($sql);
129 $this->starttime = time();
121 130 if (!$statement || if (!$statement ||
122 $statement->execute([$this->buildset,
131 $statement->execute([$this->starttime, $this->buildset,
123 132 $this->buildername]) === false) { $this->buildername]) === false) {
124 133 die("Failed to mark build as started\n" die("Failed to mark build as started\n"
125 134 . print_r(DB::errorInfo(), true)); . print_r(DB::errorInfo(), true));
 
... ... class Build
141 150 die("Failed to compress output."); die("Failed to compress output.");
142 151 } }
143 152
144 $sql = 'UPDATE builds SET status = ?, output = ?, exitcode = ? '
153 $sql = 'UPDATE builds SET status = ?, endtime = ?, output = ?, '
154 . ' exitcode = ? '
145 155 . 'WHERE buildset = ? AND buildername = ?'; . 'WHERE buildset = ? AND buildername = ?';
146 156 $statement = DB::prepare($sql); $statement = DB::prepare($sql);
157 $this->endtime = time();
147 158 if (!$statement || if (!$statement ||
148 $statement->execute([$status, $output, $exitcode, $this->buildset,
159 $statement->execute([$status, $this->endtime, $output, $exitcode,
160 $this->buildset,
149 161 $this->buildername]) === false) { $this->buildername]) === false) {
150 162 die("Failed to set build status to '$status'\n" die("Failed to set build status to '$status'\n"
151 163 . print_r(DB::errorInfo(), true)); . print_r(DB::errorInfo(), true));
 
... ... class Build
154 166 $this->status = $status; $this->status = $status;
155 167 } }
156 168
169 /**
170 * @brief Retrieves duration of the build.
171 *
172 * @returns `-1` for unknown duration, and `>= 0` value otherwise.
173 */
174 public function getDuration()
175 {
176 if ($this->endtime == 0 && $this->starttime != 0) {
177 // the build must be in progress now
178 return time() - $this->starttime;
179 }
180 return ($this->endtime == 0 || $this->starttime == 0)
181 ? -1
182 : $this->endtime - $this->starttime;
183 }
184
157 185 /** /**
158 186 * @brief ID of buildset to which this build belongs to. * @brief ID of buildset to which this build belongs to.
159 187 */ */
 
... ... class Build
178 206 * @brief Revision string, which might be @c null (depends on construction). * @brief Revision string, which might be @c null (depends on construction).
179 207 */ */
180 208 public $revision; public $revision;
209
210 /**
211 * @brief UNIX timestamp of start of processing.
212 */
213 private $starttime;
214
215 /**
216 * @brief UNIX timestamp of end of processing.
217 */
218 private $endtime;
181 219 } }
182 220
183 221 ?> ?>
File classes/Builds.php changed (mode: 100644) (index 5b9ff41..710cc5b)
... ... class Builds
35 35 */ */
36 36 public static function getBuildsForAll($buildsets) public static function getBuildsForAll($buildsets)
37 37 { {
38 $sql = 'SELECT buildset, buildername, status, exitcode FROM builds '
38 $sql = 'SELECT buildset, buildername, status, exitcode, '
39 . ' starttime, endtime '
40 . 'FROM builds '
39 41 . 'WHERE buildset=' . 'WHERE buildset='
40 42 . join(' OR buildset=', . join(' OR buildset=',
41 43 array_map('Builds::getPlaceholder', $buildsets)); array_map('Builds::getPlaceholder', $buildsets));
 
... ... class Builds
50 52 */ */
51 53 public static function getPendingBuilds() public static function getPendingBuilds()
52 54 { {
53 $sql = 'SELECT buildset, buildername, status, exitcode, revision '
55 $sql = 'SELECT buildset, buildername, status, exitcode, revision, '
56 . ' starttime, endtime '
54 57 . 'FROM builds, buildsets ' . 'FROM builds, buildsets '
55 58 . 'WHERE status = "pending" ' . 'WHERE status = "pending" '
56 59 . ' AND builds.buildset = buildsets.buildsetid ' . ' AND builds.buildset = buildsets.buildsetid '
 
... ... class Builds
89 92 $buildinfo['buildername'], $buildinfo['buildername'],
90 93 $buildinfo['status'], $buildinfo['status'],
91 94 $buildinfo['exitcode'], $buildinfo['exitcode'],
92 $revision));
95 $revision,
96 $buildinfo['starttime'],
97 $buildinfo['endtime']));
93 98 } }
94 99
95 100 return $builds; return $builds;
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/fragile

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/fragile

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master