|
|
|
@ -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({ |
|
|
|
|