From ff7ddbc61ef1328735465dce906327afab150f85 Mon Sep 17 00:00:00 2001 From: Alexey Melezhik Date: Wed, 10 Jan 2024 12:19:14 +0300 Subject: [PATCH] pulling build in queue --- bin/sparky-web.raku | 40 +++++++++++++++++++++++++++++++++-- templates/build.crotmp | 48 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/bin/sparky-web.raku b/bin/sparky-web.raku index 7b2b3b4..82f3cd5 100644 --- a/bin/sparky-web.raku +++ b/bin/sparky-web.raku @@ -82,16 +82,15 @@ sub create-cro-app ($pool) { $dbh.dispose; if $state.defined { - #content 'text/plain', "$state" if $state == -1 or $state == 1 { say "ws: done - job has finsihed - state: [$state]"; $done = True; last(); } } else { + say "ws: done - job not found"; $done = True; last(); - #not-found(); } } @@ -518,6 +517,41 @@ sub create-cro-app ($pool) { } } + get -> 'livestatus', $project, $key { + + web-socket -> $incoming { + supply { + whenever $incoming -> $message { + my $done = False; + while True { + if trigger-exists($root,$project,$key) { + emit "[{DateTime.now}] - build in queue"; + sleep(1); + } else { + my $dbh = $pool ?? $pool.get-connection() !! get-dbh(); + my $sth = $dbh.prepare("SELECT state, id FROM builds where project = '{$project}' and job_id = '{$key}'"); + $sth.execute(); + my @r = $sth.allrows(:array-of-hash); + my $build_id = @r[0]; + $sth.finish; + $dbh.dispose; + if $build_id { + say "ws - build has started, build_id: {$build_id}"; + emit "[{DateTime.now}] - build_id: {$build_id} has started"; + $done = True; + last(); + } + } + } + if $done { + # emit "[{DateTime.now}] ---"; + done + } + } + } + } + } + get -> 'report', 'raw', $project, $key { if trigger-exists($root,$project,$key) { @@ -641,6 +675,8 @@ sub create-cro-app ($pool) { template 'templates/build.crotmp', { http-root => sparky-http-root(), + sparky-host => "10.7.98.245", # fix me + sparky-tcp-port => sparky-tcp-port(), css =>css(), navbar => navbar(), project => $project, diff --git a/templates/build.crotmp b/templates/build.crotmp index 9f40455..70fd409 100644 --- a/templates/build.crotmp +++ b/templates/build.crotmp @@ -5,12 +5,14 @@ <&HTML-AND-JAVASCRIPT(.navbar)>
-

+

Build: <.project>

+
+
<@vars: $i>
@@ -58,19 +60,49 @@