* Finished getting the Jobs page working. Needs more testing, but seems to be working fine.

* Created Job->html_list() to return the list of running or recently completed jobs, and used it instead of the code formarly used in 'striker' when Striker was unavailable.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent 3c980a5c6d
commit 9fd0aa3e0f
  1. 96
      Anvil/Tools/Job.pm
  2. 97
      cgi-bin/striker
  3. 2
      html/skins/alteeve/main.html
  4. 23
      html/skins/alteeve/striker.html
  5. 1
      share/words.xml

@ -14,6 +14,7 @@ my $THIS_FILE = "Job.pm";
### Methods;
# clear
# get_job_uuid
# html_list
# running
# update_progress
@ -228,6 +229,101 @@ AND
return($jobs_running);
}
=head2 html_list
This returns an html form list of jobs that are running or recently ended.
Parameters;
=head3 ended_within (optional, default '300')
This gets a list of all jobs that are running, or that have ended within this number of seconds.
=cut
sub html_list
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $ended_within = defined $parameter->{ended_within} ? $parameter->{ended_within} : 300;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
ended_within => $ended_within,
}});
my $jobs_list = "#!string!striker_0097!#";
my $return = $anvil->Database->get_jobs({ended_within => 300});
my $count = @{$return};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, 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 => $debug, 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,
}});
# Skip jobs that finished more than five minutes ago.
my $job_finished = time - $job_updated;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:time' => time,
's2:job_updated' => $job_updated,
's3:job_finished' => $job_finished,
}});
if (($job_progress eq "100") && ($job_finished > 600))
{
# Skip it
next;
}
# 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 => $debug, 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,
progress_percent => "job_progress_percent_".$job_uuid,
status => "job_status_".$job_uuid,
}});
$jobs_list .= $job_template."\n";
}
}
return($jobs_list);
}
=head2 update_progress
This updates the progress if we were called with a job UUID.

@ -249,6 +249,10 @@ sub process_task
{
process_anvil_menu($anvil);
}
elsif ($anvil->data->{cgi}{jobs}{value})
{
process_jobs_menu($anvil);
}
else
{
# Load the main page.
@ -360,6 +364,26 @@ sub process_striker_menu
return(0);
}
# This shows the user any running jobs.
sub process_jobs_menu
{
my ($anvil) = @_;
$anvil->data->{form}{back_link} = "?striker=true";
$anvil->data->{cgi}{task}{value} = "" if not defined $anvil->data->{cgi}{task}{value};
$anvil->data->{cgi}{action}{value} = "" if not defined $anvil->data->{cgi}{action}{value};
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "jobs", variables => {
title_id => "",
message_id => "",
title => "#!string!striker_0096!#",
description => "#!string!striker_0115!#",
job_list => $anvil->Job->html_list({debug => 2, ended_within => 300}),
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { 'say::maintenance' => $anvil->data->{say}{maintenance} }});
return(0);
}
# This handles the "Anvil" menu items.
sub process_anvil_menu
{
@ -1134,81 +1158,12 @@ sub check_availability
$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({ended_within => 300});
my $count = @{$return};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, 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 => $debug, 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,
}});
# Skip jobs that finished more than five minutes ago.
my $job_finished = time - $job_updated;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:time' => time,
's2:job_updated' => $job_updated,
's3:job_finished' => $job_finished,
}});
if (($job_progress eq "100") && ($job_finished > 600))
{
# Skip it
next;
}
# 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 => $debug, 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,
progress_percent => "job_progress_percent_".$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 => "",
title => "#!string!striker_0046!#",
description => $anvil->Words->string({key => "striker_0090", variables => { }}),
job_list => $jobs_list
description => $anvil->Words->string({key => "striker_0090", variables => {} }),
job_list => $anvil->Job->html_list({debug => 2, ended_within => 300}),
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { 'say::maintenance' => $anvil->data->{say}{maintenance} }});
}

@ -56,7 +56,7 @@
<!-- end button_bar_right -->
<!-- start jobs_button_off -->
<img src="#!data!skin::url!#/images/tasks_no-jobs_icon.png" class="top_icon">
<a href="?jobs=true"><img src="#!data!skin::url!#/images/tasks_no-jobs_icon.png" class="top_icon"></a>
<!-- end jobs_button_off -->
<!-- start jobs_button_on -->

@ -138,6 +138,29 @@
</table>
<!-- end confirm-reconfig -->
<!-- start jobs -->
<table class="centered" width="90%">
<tr>
<td>
&nbsp;
</td>
</tr>
<div id="running_jobs">
<script type="text/javascript" src="/skins/alteeve/jobs.js"></script>
<tr>
<td>
<input type="hidden" name="status_waiting" id="status_waiting" value="#!string!js_0004!#">
<span name="jobs-title" id="jobs-title" class="config_header2">#!string!header_0011!#</span><br />
<span name="jobs-message" id="jobs-message" class="config_header3">#!string!striker_0096!#</span>
<br />
<hr />
#!variable!job_list!#
</td>
</tr>
</div>
</table>
<!-- end jobs -->
<!-- start reconfig-done -->
<table>
<tr>

@ -695,6 +695,7 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="striker_0112">The 'Install Target' enabled job has been requested. It should be completed in a few moments. You may need to reload the next page in a minute to see that it has been disabled.</key>
<key name="striker_0113">Anvil! Configuration and Management.</key>
<key name="striker_0114">Create a new Anvil! system.</key>
<key name="striker_0115">Any running jobs, or jobs that have ended recently, are displayed below.</key>
<!-- Strings used by jobs -->
<key name="job_0001">Configure Network</key>

Loading…
Cancel
Save