* Made more progress on anvil-daemon's invokation of jobs.

* Got anvil-update-system clearing job data when (re)starting

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent 1d31593ea6
commit bd862b2e5e
  1. 5
      Anvil/Tools/System.pm
  2. 2
      share/words.xml
  3. 6
      tools/anvil-daemon
  4. 51
      tools/anvil-update-system

@ -244,9 +244,14 @@ sub call
$process->redirect_output(undef, $stderr_file);
}
# Start the process
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, key => "log_0204", variables => { call => $shell_call }});
my $status = $process->start($shell_call);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, list => { status => $status }});
# Report that it started with PID.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, key => "log_0205", variables => { call => $shell_call, pid => $process->pid }});
# We'll return the handle instead of output.
$output = $process;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, list => { output => $output }});

@ -327,6 +327,8 @@ The database connection error was:
<key name="log_0201">Unable to connect to any database. Will try to initialize the local system and then try again.</key>
<key name="log_0202">Failed to connect to any databases. Skipping the loop of the daemon.</key>
<key name="log_0203">Disconnected from all databases. Will reconnect when entering the main loop.</key>
<key name="log_0204">Starting the background process: [#!variable!call!#] now.</key>
<key name="log_0205">Background process: [#!variable!call!#] running with PID: [#!variable!pid!#].</key>
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
<key name="t_0000">Test</key>

@ -315,14 +315,15 @@ WHERE
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 => 0, priority => "alert", key => "striker_warning_0007", variables => {
$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
{
# Start the job, appending '--job-uuid' to the command.
$anvil->data->{jobs}{handles}{$job_uuid} = $anvil->System->call({
debug => 2,
@ -350,6 +351,7 @@ WHERE
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}
}
# Close the jobs file.
$jobs_file .= "]}\n";

@ -15,6 +15,7 @@
# 1 = No database connections available.
# 2 = The job UUID was passed, but it wasn't valid.
# 3 = It looks like the update failed, reset progress to '0'.
#
use strict;
use warnings;
@ -38,6 +39,9 @@ $anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
$anvil->data->{switches}{'job-uuid'} = "";
$anvil->Get->switches;
# Log that we've started.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Connect to DBs.
$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"});
@ -50,6 +54,7 @@ if (not $anvil->data->{sys}{database}{connections})
}
# Did we get called with a job UUID?
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::job-uuid" => $anvil->data->{switches}{'job-uuid'} }});
if ($anvil->data->{switches}{'job-uuid'})
{
# Is it set and valid?
@ -106,11 +111,14 @@ WHERE
}});
}
# Clea any old runs.
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");
print $THIS_FILE." running with PID: [".$$."]\n"
sleep 60;
print $THIS_FILE."; time: [".time."], exiting\n";
exit;
run_os_update($anvil);
@ -140,11 +148,23 @@ sub update_progress
my ($anvil, $progress, $message) = @_;
# Log the progress percentage.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { progress => $progress }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
progress => $progress,
message => $message,
"jobs::job_uuid" => $anvil->data->{jobs}{job_uuid},
}});
if ($anvil->data->{jobs}{job_uuid})
{
# Get the current job_status and append this new one.
my $job_picked_up_by = $$;
my $job_status = "";
if ($message eq "clear")
{
$job_picked_up_by = 0;
}
else
{
my $query = "
SELECT
job_status
@ -153,26 +173,31 @@ FROM
WHERE
job_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{jobs}{job_uuid})."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $job_status = $anvil->Database->query({uuid => $uuid, debug => $debug, query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$job_status = "" if not defined $old_job_status;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { job_status => $job_status }});
$job_status = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$job_status = "" if not defined $job_status;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_status => $job_status }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { message => $message }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { message => $message }});
if ($job_status)
{
$job_status .= "\n";
}
if ($message)
{
$job_status .= $message."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { job_status => $job_status }});
$job_status .= $message;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_status => $job_status }});
}
}
my $query = "
UPDATE
jobs
SET
job_picked_up_by = ".$anvil->data->{sys}{database}{use_handle}->quote($$).",
job_updated = now(),
job_progress = ".$progress.",
job_picked_up_by = ".$anvil->data->{sys}{database}{use_handle}->quote($job_picked_up_by).",
job_updated = ".time.",
job_progress = ".$anvil->data->{sys}{database}{use_handle}->quote($progress).",
job_status = ".$anvil->data->{sys}{database}{use_handle}->quote($job_status).",
modified_date = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{sys}{database}{timestamp})."
WHERE

Loading…
Cancel
Save