summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-06-26 12:57:57 -0400
committerEudyptula <eitan@mosenkis.net>2009-06-26 12:57:57 -0400
commit4699a267d7099a4d42dd25c625cb50a6ff5777c7 (patch)
treebe7b9b461951696ee693aa32b1262953abc114c8 /shared
parentAdded signal handling and logging; wrote init script; added other nice daemon... (diff)
downloadingenue-4699a267d7099a4d42dd25c625cb50a6ff5777c7.tar.gz
ingenue-4699a267d7099a4d42dd25c625cb50a6ff5777c7.tar.bz2
ingenue-4699a267d7099a4d42dd25c625cb50a6ff5777c7.zip
Changed task to have an index based on build instead of unique id, added description field
Diffstat (limited to 'shared')
-rw-r--r--shared/classes/build.php6
-rw-r--r--shared/classes/buildlog.php33
-rw-r--r--shared/classes/buildlog_entry.php (renamed from shared/classes/commandlog_entry.php)14
-rw-r--r--shared/classes/registrationtoken.php1
-rw-r--r--shared/classes/task.php53
-rw-r--r--shared/include/dbinit.php6
6 files changed, 55 insertions, 58 deletions
diff --git a/shared/classes/build.php b/shared/classes/build.php
index 369425e..fd02aa9 100644
--- a/shared/classes/build.php
+++ b/shared/classes/build.php
@@ -90,16 +90,16 @@ class sql_build extends sql_row_obj {
} elseif ($status[1]='running') {
// Add link to regular log viewer?
// Build stage X
- $html.='<span class="status building">[building]</span><br/><span class="links"><a href="'.url('logs/build'.$this->id.'/live').'">Watch</a></span>';
+ $html.='<span class="status building">[building]</span><br/><span class="links"><a href="'.url('logs/'.$this->id.'/live').'">Watch</a></span>';
} else {
throw_exception('Unrecognized build status '.$this->status);
}
} elseif ($status[0] == 'finished') {
$status=explode(': ', $status[1], 2);
if ($status[0] == 'success') {
- $html.='<span class="status successful">[successful]</span><br/><span class="links"><a href="'.url('download/'.$this->id).'">Download image</a> &bull; <a href="'.url('logs/build'.$this->id).'">Build log</a></span>';
+ $html.='<span class="status successful">[successful]</span><br/><span class="links"><a href="'.url('download/'.$this->id).'">Download image</a> &bull; <a href="'.url('logs/'.$this->id).'">Build log</a></span>';
} elseif ($status[0] == 'failed') {
- $html.='<span class="status failed">[failed: '.htmlentities($status[1]).']</span><br/><span class="links"><a href="'.url('logs/build'.$this->id.'/failure').'">View output of failed command</a> &bull; <a href="'.url('logs/build'.$this->id).'">Build log</a></span>';
+ $html.='<span class="status failed">[failed: '.htmlentities($status[1]).']</span><br/><span class="links"><a href="'.url('logs/'.$this->id.'/failure').'">View output of failed command</a> &bull; <a href="'.url('logs/'.$this->id).'">Build log</a></span>';
} else {
throw_exception('Unrecognized build status '.$this->status);
}
diff --git a/shared/classes/buildlog.php b/shared/classes/buildlog.php
deleted file mode 100644
index 5ba95f6..0000000
--- a/shared/classes/buildlog.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-class sql_buildlog extends sql_row_obj {
- protected $table='buildlogs', $primary_key=array('build', 'order'), $columns=array(
- 'build' => array (
- 'type' => 'CHAR',
- 'length' => 6,
- 'not_null' => true,
- 'default' => ''
- ),
- 'order' => array (
- 'type' => 'TINYINT',
- 'length' => 3,
- 'unsigned' => true,
- 'not_null' => true,
- 'default' => 0
- ),
- 'type' => array (
- 'type' => 'ENUM',
- 'length' => '\'command\',\'system\',\'msg\'',
- 'not_null' => true
- ),
- 'id' => array (
- 'type' => 'INT',
- 'length' => 10,
- 'unsigned' => true
- ),
- 'msg' => array (
- 'type' => 'TEXT'
- )
-
- );
-}
-?>
diff --git a/shared/classes/commandlog_entry.php b/shared/classes/buildlog_entry.php
index 5f78aab..5b8c380 100644
--- a/shared/classes/commandlog_entry.php
+++ b/shared/classes/buildlog_entry.php
@@ -1,9 +1,15 @@
<?php
-class sql_commandlog_entry extends sql_row_obj {
- protected $table='commandlogs', $columns=array(
+class sql_buildlog_entry extends sql_row_obj {
+ protected $table='buildlogs', $primary_key=array('build', 'task', 'order'), $columns=array(
+ 'build' => array (
+ 'type' => 'CHAR',
+ 'length' => 6,
+ 'not_null' => true,
+ 'default' => ''
+ ),
'task' => array (
- 'type' => 'INT',
- 'length' => 10,
+ 'type' => 'TINYINT',
+ 'length' => 3,
'unsigned' => true,
'not_null' => true,
'default' => 0
diff --git a/shared/classes/registrationtoken.php b/shared/classes/registrationtoken.php
index 86e8d44..9f331ae 100644
--- a/shared/classes/registrationtoken.php
+++ b/shared/classes/registrationtoken.php
@@ -16,6 +16,7 @@ class sql_registrationtoken extends sql_row_obj {
'type' => 'VARCHAR',
'length' => 255,
'not_null' => true,
+ 'default' => '',
'unique' => true
),
'expire' => array (
diff --git a/shared/classes/task.php b/shared/classes/task.php
index ba8db5e..2fb7c68 100644
--- a/shared/classes/task.php
+++ b/shared/classes/task.php
@@ -1,13 +1,6 @@
<?php
class sql_task extends sql_row_obj {
- protected $table='tasks', $primary_key=array('id'), $columns=array(
- 'id' => array (
- 'type' => 'INT',
- 'length' => 10,
- 'unsigned' => true,
- 'not_null' => true,
- 'auto_increment' => true
- ),
+ protected $table='tasks', $primary_key=array('build', 'order'), $columns=array(
'build' => array (
'type' => 'CHAR',
'length' => 6,
@@ -15,6 +8,23 @@ class sql_task extends sql_row_obj {
'default' => '',
'refers_to' => 'builds.id'
),
+ 'order' => array (
+ 'type' => 'TINYINT',
+ 'length' => 4,
+ 'not_null' => true,
+ 'default' => 0
+ ),
+ 'type' => array (
+ 'type' => 'ENUM',
+ 'length' => '\'exec\',\'internal\'',
+ 'not_null' => true
+ ),
+ 'description' => array (
+ 'type' => 'VARCHAR',
+ 'length' => 255,
+ 'not_null' => true,
+ 'default' => ''
+ ),
'command' => array (
'type' => 'TEXT',
'not_null' => true
@@ -36,7 +46,7 @@ class sql_task extends sql_row_obj {
);
function display() {
- $html='<div class="task">[<a href="'.url('logs/task'.$this->id).'">log</a>] <span class="command">'.htmlentities($this->command).'</span> ';
+ $html='<div class="task"><div class="description">'.htmlentities($this->description).'</div><div class="info">[<a href="'.url('logs/'.$this->build.'/'.$this->order).'">log</a>] <span class="command">'.htmlentities($this->command).'</span> ';
if (isset($this->start)) {
if (isset($this->finish)) {
$html.='<span class="status ';
@@ -57,18 +67,19 @@ class sql_task extends sql_row_obj {
}
} else {
$total=$S['pdo']->query('SELECT COUNT(*) FROM `tasks` WHERE `build`="'.$this->build.'" AND `start` IS NULL')->fetch(PDO::FETCH_COLUMN);
- $num=$S['pdo']->query('SELECT COUNT(*) FROM `tasks` WHERE `builds`="'.$this->build.'" AND `start` IS NULL AND `id` <= '.$this->id);
+ $num=$S['pdo']->query('SELECT COUNT(*) FROM `tasks` WHERE `builds`="'.$this->build.'" AND `start` IS NULL AND `order` <= '.$this->order);
$html.="<span class=\"status queued\">[queued $num/$total]</span>";
}
- $html.='</div>';
+ $html.='</div></div>';
return $html;
}
function execute($fatal=true, $path=null, $env=null) {
- if (!isset($this->command, $this->build)) {
- throw_exception('$this->command or $this->build not set');
+ if (!isset($this->command, $this->build, $this->order)) {
+ throw_exception('$this->command, $this->build, or $this->order not set');
} elseif (isset($this->start)) {
throw_exception('task has already executed: start is '.$this->start);
}
+ $this->type='exec';
log_msg('Executing '.$this->command.'...', false);
$descriptorspec=array(
0 => array('pipe', 'r'), // STDIN
@@ -91,13 +102,13 @@ class sql_task extends sql_row_obj {
$c=stream_get_contents($pipes[2]);
if ($c) {
// STDERR
- $entry=new sql_commandlog_entry($this->id, $msg++, time(), 'stderr', $c);
+ $entry=new sql_buildlog_entry($this->build, $this->order, $msg++, time(), 'stderr', $c);
$entry->write();
}
$c=stream_get_contents($pipes[1]);
if ($c) {
// STDOUT
- $entry=new sql_commandlog_entry($this->id, $msg++, time(), 'stdout', $c);
+ $entry=new sql_buildlog_entry($this->build, $this->order, $msg++, time(), 'stdout', $c);
$entry->write();
}
}
@@ -140,10 +151,18 @@ class sql_task extends sql_row_obj {
}
return $this->exit;
}
- static function execute_task($command, $build, $fatal=true, $path=null, $env=null) {
+ static function execute_command($description, $command, $build, $fatal=true, $path=null, $env=null) {
global $task;
- $task=new sql_task(null, is_object($build)?$build->id:$build, $command);
+ // TODO this won't work once we have internal tasks too - we need to modify the build class to track its own task IDs
+ static $buildid=null;
+ static $order=0;
+ if ($build->id !== $buildid) {
+ $buildid=$build->id;
+ $order=0;
+ }
+ $task=new sql_task($build->id, $order, null, $description, $command);
$result=$task->execute($fatal, $path, $env);
+ $order++;
unset($task);
return $result;
}
diff --git a/shared/include/dbinit.php b/shared/include/dbinit.php
index 3b19689..e52498a 100644
--- a/shared/include/dbinit.php
+++ b/shared/include/dbinit.php
@@ -1,7 +1,11 @@
<?php
require_once(dirname(__FILE__).'/../config.php'); // Use __DIR__ in 5.3.0
$pdoclass=(class_exists('pdo_debug')?'pdo_debug':'PDO');
-$S['pdo']=new $pdoclass('mysql:dbname='.$conf['sqldb'].';host='.$conf['sqlhost'], $conf['sqluser'], $conf['sqlpass']);
+try {
+ $S['pdo']=new $pdoclass('mysql:dbname='.$conf['sqldb'].';host='.$conf['sqlhost'], $conf['sqluser'], $conf['sqlpass'], array(PDO::ATTR_PERSISTENT => true));
+} catch (Exception $e) {
+ die(print_error('Database connection failure.', $e->getMessage()));
+}
unset($pdoclass);
sql_row_obj::set_pdo_obj($S['pdo']);
?>