summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'backend/functions/execution.php')
-rw-r--r--backend/functions/execution.php12
1 files changed, 9 insertions, 3 deletions
diff --git a/backend/functions/execution.php b/backend/functions/execution.php
index c201adf..73cef31 100644
--- a/backend/functions/execution.php
+++ b/backend/functions/execution.php
@@ -1,11 +1,14 @@
<?php
+// TODO this should be part of the task class
function log_command(&$build, $command, $path=null, $env=null) {
+ log_msg("Executing $command... ", false);
$descriptorspec=array(
0 => array('pipe', 'r'), // STDIN
1 => array('pipe', 'w'), // STDOUT
2 => array('pipe', 'w') // STDERR
);
$task=new sql_task(null, $build->id, $command, null);
+ $task->start=time();
$task->write();
$p=proc_open($command, $descriptorspec, $pipes, $path, $env);
foreach ($pipes as $pipe) {
@@ -20,19 +23,16 @@ function log_command(&$build, $command, $path=null, $env=null) {
$s=stream_select($outs, $null, $null, 1);
if ($s) {
$c=stream_get_contents($pipes[2]);
- // TODO this really needs to go to the DB and carry metadata
if ($c) {
// STDERR
$entry=new sql_buildlog_entry($task->id, $msg++, time(), 'stderr', $c);
$entry->write();
- //log_msg($c, false);
}
$c=stream_get_contents($pipes[1]);
if ($c) {
// STDOUT
$entry=new sql_buildlog_entry($task->id, $msg++, time(), 'stdout', $c);
$entry->write();
- //log_msg($c, false);
}
}
if ($status['running'] === false) {
@@ -40,6 +40,7 @@ function log_command(&$build, $command, $path=null, $env=null) {
break;
}
}
+ $task->finish=time();
foreach ($pipes as $pipe) {
fclose($pipe);
}
@@ -48,6 +49,11 @@ function log_command(&$build, $command, $path=null, $env=null) {
}
$task->exit=$exit_status;
$task->write();
+ if ($exit_status == 0) {
+ log_msg(color('[success]', 'green'));
+ } else {
+ log_msg(color('[exit code '.$exit_status.']', 'red'));
+ }
// Handle end status
return $exit_status;
}