summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'backend/functions/execution.php')
-rw-r--r--backend/functions/execution.php67
1 files changed, 59 insertions, 8 deletions
diff --git a/backend/functions/execution.php b/backend/functions/execution.php
index dd6dd88..773e6ee 100644
--- a/backend/functions/execution.php
+++ b/backend/functions/execution.php
@@ -1,18 +1,25 @@
<?php
+function task_get_order() {
+ global $build;
+ static $buildid=null;
+ static $order=null;
+ if ($build->id === $buildid) {
+ $order++;
+ } else {
+ $buildid=$build->id;
+ $order=0;
+ }
+ return $order;
+}
function execute_command_with_all($description, $command, $fatal=true, $path=null, $env=null) {
global $build, $task;
+ if (isset($task))
+ end_internal_task();
$default_env=array(
'PATH' => $_ENV['PATH']
);
$env=is_array($env)?array_merge($default_env, $env):$default_env;
- // TODO this won't work once we have internal tasks too - we need to use a common function for tracking order
- 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);
+ $task=new sql_task($build->id, task_get_order(), 'exec', $description, $command);
$result=$task->execute($path, $env);
unset($task);
if ($result != 0 && $fatal) {
@@ -37,4 +44,48 @@ function execute_command_with_path($desc, $cmd, $path) {
function execute_non_fatal_command($desc, $cmd, $path=null, $env=null) {
return execute_command_with_all($desc, $cmd, false, $path, $env);
}
+function start_internal_task($desc) {
+ global $build, $task;
+ if (isset($task))
+ end_internal_task();
+ debug($desc);
+ $task=new sql_task($build->id, task_get_order(), 'internal', $desc);
+ $task->start=time();
+ $task->write();
+}
+function end_internal_task($status=0) {
+ global $task;
+ if (isset($task)) {
+ $task->finish=time();
+ $task->exit=$status;
+ $task->write();
+ unset($task);
+ }
+}
+function log_msg($msg, $nl=true) {
+ global $build, $task;
+ static $order, $buildid, $taskorder;
+ if (!isset($task)) {
+ start_internal_task($msg);
+ return;
+ }
+ $msg.=$nl?"\n":'';
+ debug($msg);
+ if ($buildid === $build->id && $taskorder === $task->order) {
+ $order++;
+ } else {
+ $buildid=$build->id;
+ $taskorder=$task->order;
+ $order=0;
+ }
+ $entry=new sql_buildlog_entry($build->id, $task->order, $order, time(), 'system', $msg);
+ $entry->write();
+}
+function log_status($msg, $cmd) {
+ start_internal_task($msg);
+ $status=is_bool($cmd)?$cmd:eval((strpos($cmd, 'return') === false?'return ':'').$cmd);
+ end_internal_task($status?0:1);
+ debug("... ".($status?color('[success]', 'green'):color('[failure]', 'red')));
+ return $status;
+}
?>