diff --git a/Anvil/Tools/Job.pm b/Anvil/Tools/Job.pm index 398995cf..02a366c9 100644 --- a/Anvil/Tools/Job.pm +++ b/Anvil/Tools/Job.pm @@ -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. diff --git a/cgi-bin/striker b/cgi-bin/striker index 8955bcb7..0df2552d 100755 --- a/cgi-bin/striker +++ b/cgi-bin/striker @@ -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 + title_id => "", + message_id => "", + title => "#!string!striker_0046!#", + 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} }}); } diff --git a/html/skins/alteeve/main.html b/html/skins/alteeve/main.html index 8c86a7d9..d8dcc61b 100644 --- a/html/skins/alteeve/main.html +++ b/html/skins/alteeve/main.html @@ -56,7 +56,7 @@ - + diff --git a/html/skins/alteeve/striker.html b/html/skins/alteeve/striker.html index c0c93853..da7a16fd 100644 --- a/html/skins/alteeve/striker.html +++ b/html/skins/alteeve/striker.html @@ -138,6 +138,29 @@ + +
+ + | +
+
+ #!string!header_0011!# + #!string!striker_0096!# + + + #!variable!job_list!# + |
+