@ -54,13 +54,17 @@ if (not $anvil->data->{sys}{database}{connections})
}
}
my $say_description = $anvil->Words->parse_banged_string({json_escape => 1, key_string => "job_0004"});
print "say_description: [".$say_description."]\n";
die;
# Read switches
$anvil->data->{switches}{'run-once'} = "";
$anvil->data->{switches}{'no-run-once'} = "";
$anvil->data->{switches}{'run-once'} = "";
$anvil->data->{switches}{'main-loop-only '} = "";
$anvil->Get->switches;
# There are some things we only want to run on (re)start and don't need to always run.
run_once($anvil) if not $anvil->data->{switches}{'no-run-once '};
run_once($anvil) if not $anvil->data->{switches}{'main-loop-only '};
# Calculate my sum so that we can exit if it changes later.
$anvil->Storage->record_md5sums;
@ -244,8 +248,6 @@ sub run_jobs
# Get a list of pending or incomplete jobs.
my $return = $anvil->Database->get_jobs({debug => 2, ended_within => 300});
my $count = @{$return};
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'return' => $return,
count => $count,
@ -272,59 +274,22 @@ sub run_jobs
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,
started_seconds_ago => $started_seconds_ago,
updated_seconds_ago => $updated_seconds_ago,
}});
# TODO: Make this a Words->decypher_string() method
my $say_progress = "";
if ($job_progress)
{
foreach my $message (split/\n/, $job_progress)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { message => $message }});
if ($message =~ /^(.*?),(.*)$/)
{
my $key = $1;
my $variable_string = $2;
my $variables = {};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
key => $key,
variable_string => $variable_string,
}});
foreach my $pair (split/,/, $variable_string)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { pair => $pair }});
my $name = "";
my $value = "";
if ($pair =~ /^!!(.*?)!(.*)!!$/)
{
$name = $1;
$value = $2;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
name => $name,
value => $value,
}});
}
elsif ($pair =~ /^!!(.*?)!!!$/)
{
$name = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { name => $name }});
}
else
{
# what?!
}
$variables->{$name} = $value;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "variables->$name" => $variables->{$name} }});
}
$say_progress = $anvil->Words->string({key => $key, variables => $variables}),
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "say_progress" => $say_progress }});
}
}
}
# Convert the double-banged strings into a proper message.
my $say_title = $job_title ? $anvil->Words->parse_banged_string({debug => 2, json_escape => 1, key_string => $job_title}) : "";
my $say_description = $job_description ? $anvil->Words->parse_banged_string({debug => 2, json_escape => 1, key_string => $job_description}) : "";
my $say_status = $job_progress ? $anvil->Words->parse_banged_string({debug => 2, json_escape => 1, key_string => $job_status}) : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
job_title => $job_title,
say_description => $say_description,
say_status => $say_status,
}});
# Add this to the jobs.json file
$jobs_file .= "{ \"job_uuid\":\"".$job_uuid."\",
@ -332,10 +297,17 @@ sub run_jobs
\"job_data\":\"".$job_data."\",
\"job_picked_up_at\":\"".$job_picked_up_at."\",
\"job_updated\":\"".$job_updated."\",
\"job_name\":\"".$job_name."\",
\"job_progress\":\"".$job_progress."\",
\"job_title\":\"".$say_title."\",
\"job_description\":\"".$say_description."\",
\"job_status\":\"".$say_status."\",
\"started_seconds_ago\":\"".$started_seconds_ago."\",
\"updated_seconds_ago\":\"".$updated_seconds_ago."\" }, \n";
# 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)
{