* The job progress display in Striker while in maintenance mode is coming along and mostly working now.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent eaca4c885f
commit eecef192b3
  1. 54
      cgi-bin/striker
  2. 2
      html/jquery-latest.js
  3. 26
      html/skins/alteeve/jobs.js
  4. 8
      html/skins/alteeve/main.css
  5. 4
      html/skins/alteeve/main.html
  6. 26
      html/skins/alteeve/striker.html
  7. 2
      rpm/SPECS/anvil.spec
  8. 1
      share/words.xml
  9. 71
      tools/anvil-daemon
  10. 32
      tools/anvil-update-system

@ -792,7 +792,61 @@ sub check_availability
$available = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { available => $available }});
# If we have any running or recently finished jobs, we'll desplay them below.
my $jobs_list = "#!string!striker_0097!#";
my $return = $anvil->Database->get_jobs({debug => 2, ended_within => 300});
my $count = @{$return};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
if ($count)
{
$jobs_list = "";
foreach my $hash_ref (@{$return})
{
my $job_uuid = $hash_ref->{job_uuid};
my $job_command = $hash_ref->{job_command};
my $job_data = $hash_ref->{job_data};
my $job_picked_up_by = $hash_ref->{job_picked_up_by};
my $job_picked_up_at = $hash_ref->{job_picked_up_at};
my $job_updated = $hash_ref->{job_updated};
my $job_name = $hash_ref->{job_name};
my $job_progress = $hash_ref->{job_progress};
my $job_title = $hash_ref->{job_title};
my $job_description = $hash_ref->{job_description};
my $job_status = $hash_ref->{job_status};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
job_uuid => $job_uuid,
job_command => $job_command,
job_data => $job_data,
job_picked_up_by => $job_picked_up_by,
job_picked_up_at => $job_picked_up_at,
job_updated => $job_updated,
job_name => $job_name,
job_progress => $job_progress,
job_title => $job_title,
}});
# Convert the double-banged strings into a proper message.
my $say_title = $job_title ? $anvil->Words->parse_banged_string({key_string => $job_title}) : "";
my $say_description = $job_description ? $anvil->Words->parse_banged_string({key_string => $job_description}) : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
job_title => $job_title,
say_description => $say_description,
}});
### TODO: left off here
my $job_template = $anvil->Template->get({file => "striker.html", name => "job-details", variables => {
div_id => "job_".$job_uuid,
title => $say_title,
description => $say_description,
progress_bar => "job_progress_".$job_uuid,
status => "job_status_".$job_uuid,
}});
$jobs_list .= $job_template."\n";
}
}
#
$anvil->data->{say}{maintenance} = $anvil->Template->get({file => "striker.html", name => "striker-offline", variables => {
title_id => "",
message_id => "",

@ -1 +1 @@
jquery-3.2.1.js
jquery-3.3.1.js

@ -0,0 +1,26 @@
$.ajaxSetup({
cache: false
});
$(function() {
if($("#running_jobs").length) {
console.log('Looking for running jobs.');
setInterval(function() {
$.getJSON('/status/jobs.json', { get_param: 'value' }, function(data) {
$.each(data.jobs, function(index, element) {
var progress = element.job_progress
console.log('entry: ['+index+'], uuid: ['+element.job_uuid+'], progress: ['+progress+']');
//console.log('status: ['+element.job_status+']');
// Initialize
$("#job_progress_"+element.job_uuid).progressbar({value: parseInt(element.job_progress)});
$("#job_status_"+element.job_uuid).html(element.job_status);
});
});
}, 1000);
}
else
{
alert('Jobs status not loaded.');
}
});

@ -301,3 +301,11 @@ td {
padding-left: 10px;
padding-right: 10px;
}
/* This is used by HTML::FromText when converting a text string to HTML */
.hft-lines {
text-align: left;
font-family: 'Dejavu Sans Mono', Courier;
padding: 0.2em;
font-size: 0.9em;
}

@ -101,6 +101,10 @@
<link rel="stylesheet" href="#!data!skin::url!#/main.css" media="screen" />
<script type="text/javascript" src="/jquery-latest.js"></script>
<script type="text/javascript" src="#!data!skin::url!#/main.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<!-- end header -->

@ -208,7 +208,8 @@
&nbsp;
</td>
</tr>
<div id="running-jobs">
<div id="running_jobs">
<script type="text/javascript" src="/skins/alteeve/jobs.js"></script>
<tr>
<td>
<span name="jobs-title" id="jobs-title" class="config_header2">#!string!header_0011!#</span><br />
@ -223,6 +224,29 @@
<!-- end striker-offline -->
<!-- start job-details -->
<div id="#!variable!div_id!#">
<br />
<table style="border: 1px solid white">
<tr>
<td width="50%">
<span class="column_header">#!variable!title!#</span>
</td>
<td width="50%">
<div id="#!variable!progress_bar!#"></div>
</td>
</tr>
<tr>
<td colspan="2">
<span class="column_row_name">#!variable!description!#</span>
</td>
</tr>
<tr>
<td colspan="2">
<div id="#!variable!status!#"></div>
</td>
</tr>
</table>
</div>
<!-- end job-details -->
<!-- start striker-setup -->

@ -35,6 +35,8 @@ Requires: perl-Data-Dumper
Requires: perl-DBD-Pg
Requires: perl-DBI
Requires: perl-Digest-SHA
Requires: perl-HTML-FromText
Requires: perl-HTML-Strip
Requires: perl-JSON
Requires: perl-Log-Journald
Requires: perl-Net-SSH2

@ -89,6 +89,7 @@ Report if a reboot is needed: #!variable!program!#
<key name="message_0053">This system needs to be rebooted.</key>
<key name="message_0054">This system does NOT need to be rebooted.</key>
<key name="message_0055">Exiting to '--run-once' switch.</key>
<key name="message_0056">Previous run exited early. Restarting momentarily.</key>
<!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key>

@ -17,6 +17,8 @@ use warnings;
use Anvil::Tools;
use Proc::Simple;
use JSON;
use HTML::Strip;
use HTML::FromText;
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
@ -274,20 +276,66 @@ sub run_jobs
job_name => $job_name,
job_progress => $job_progress,
job_title => $job_title,
job_description => $job_description,
job_status => $job_status,
started_seconds_ago => $started_seconds_ago,
updated_seconds_ago => $updated_seconds_ago,
}});
# See if the job was picked up by a now-dead instance.
if ($job_picked_up_by)
{
# Check if the PID is still active.
$anvil->System->pids({ignore_me => 1});
### TODO: Add a check to verify the job isn't hung.
# Skip if this job is in progress.
if (not exists $anvil->data->{pids}{$job_picked_up_by})
{
# The previous job is gone, but the job isn't finished. Start it again.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "striker_warning_0007", variables => {
command => $job_command,
pid => $job_picked_up_by,
percent => $job_progress,
}});
clear_job($anvil, $job_uuid);
# Clear some variables.
$job_picked_up_by = 0;
$job_progress = 0;
$job_status = "message_0056";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
job_picked_up_by => $job_picked_up_by,
job_progress => $job_progress,
job_status => $job_status,
}});
}
}
# Convert the double-banged strings into a proper message.
my $say_title = $job_title ? $anvil->Words->parse_banged_string({key_string => $job_title}) : "";
my $say_description = $job_description ? $anvil->Words->parse_banged_string({key_string => $job_description}) : "";
my $say_status = $job_progress ? $anvil->Words->parse_banged_string({key_string => $job_status}) : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
job_title => $job_title,
say_description => $say_description,
say_status => $say_status,
}});
# Make the status HTML friendly. Strip any embedded HTML then encode the text string.
my $html_strip = HTML::Strip->new();
$say_status = $html_strip->parse($say_status);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_status => $say_status }});
# Now make the resulting text string HTML friendly
my $text_to_html = HTML::FromText->new({
urls => 1,
email => 1,
lines => 1,
});
$say_status = $text_to_html->parse($say_status);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_status => $say_status }});
# Add this to the jobs.json file
my $json_string = to_json ({
job_uuid => $job_uuid,
@ -309,25 +357,8 @@ sub run_jobs
# If the job is done, move on.
next if $job_progress eq "100";
# See if the job was picked up by another running instance.
if ($job_picked_up_by)
{
# Check if the PID is still active.
$anvil->System->pids({ignore_me => 1});
### TODO: Add a check to verify the job isn't hung.
# Skip if this job is in progress.
next if exists $anvil->data->{pids}{$job_picked_up_by};
# The previous job is gone, but the job isn't finished. Start it again.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "striker_warning_0007", variables => {
command => $job_command,
pid => $job_picked_up_by,
percent => $job_progress,
}});
clear_job($anvil, $job_uuid);
}
else
# If the job is not running, start it.
if (not $job_picked_up_by)
{
# Start the job, appending '--job-uuid' to the command.
$anvil->data->{jobs}{handles}{$job_uuid} = $anvil->System->call({

@ -144,14 +144,9 @@ WHERE
update_progress($anvil, 0, "clear");
# Mark that we're starting
print $THIS_FILE."; time: [".time."], running with PID: [".$$."]\n";
update_progress($anvil, 1, "message_0033");
sleep 10;
print $THIS_FILE."; time: [".time."], exiting\n";
update_progress($anvil, 2, "message_0035,!!size!42M!!");
update_progress($anvil, 3, "message_0017,!!hostname!neutron!!,!!bad_hostname!mermaid!!");
exit;
# Run the update
run_os_update($anvil);
# We're done updating
@ -226,7 +221,7 @@ WHERE
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { message => $message }});
if ($job_status)
if (($message) && ($job_status))
{
$job_status .= "\n";
}
@ -263,14 +258,15 @@ sub run_os_update
my ($anvil) = @_;
# NOTE: We run this directly to better monitor progress and update the progress.
my $success = 0;
my $to_update = 0;
my $percent_step = 0;
my $progress = 5;
my $counted_lines = 0;
my $next_step = 0;
my $verifying = 0;
my $output = "";
my $transaction_shown = 0;
my $success = 0;
my $to_update = 0;
my $percent_step = 0;
my $progress = 5;
my $counted_lines = 0;
my $next_step = 0;
my $verifying = 0;
my $output = "";
my $shell_call = $anvil->data->{path}{exe}{dnf}." clean expire-cache && ".$anvil->data->{path}{exe}{dnf}." -y update; ".$anvil->data->{path}{exe}{echo}." return_code:\$?";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }});
@ -301,7 +297,11 @@ sub run_os_update
if ($line =~ /Running transaction/i)
{
# Done downloading
update_progress($anvil, $progress, "message_0037");
if (not $transaction_shown)
{
update_progress($anvil, $progress, "message_0037");
$transaction_shown = 1;
}
}
if ($line =~ /return_code:(\d+)$/)

Loading…
Cancel
Save