summaryrefslogtreecommitdiff
blob: 0dbd8a9e34a32ca402173dfeba2bf4b57b32b647 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/php
<?php
require_once(dirname(__FILE__).'/../shared/include/includes.php'); // USE __DIR__ once 5.3.0 is out
require_once(SHARED.'/config.php');
require_once(SHARED.'/include/dbinit.php');
$pdo=&$S['pdo'];
$opts=getopt('f');
if (isset($opts['f'])) {
	$f=pcntl_fork();
	switch($f) {
	case -1:
		die("Failed to fork");
	case 0:
		echo "Forked.  Commiting suicide.\n";
		exit;
	default:
		echo "I am the child!\n";
	}
}
while (true) {
	// TODO check first for builds that need to be resumed
	$r=$pdo->query('SELECT * FROM `builds` WHERE `status`="build/ready" ORDER BY `ctime` ASC LIMIT 1');
	if ($r->rowCount()) {
		$build=new sql_build($r->fetch(PDO::FETCH_ASSOC));
		$build->start=time();
		$build->write();
		echo 'Starting build id='.$build->id."\n";
		try {
			build($build);
		} catch (Exception $e) {
			echo 'Caught exception: '.$e->getMessage()."\n";
		}
		$build->finish=time();
		$build->write();
		echo 'Finished with build id='.$build->id."\n";
	}
	echo 'Sleeping...';
	sleep(5);
	echo "done\n";
}
?>