Updates Jobs->update_progress() to take a 'variables' hash reference, and to support logging as well.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 3 years ago
parent 1e159f548e
commit 548c52701a
  1. 48
      Anvil/Tools/Job.pm
  2. 10
      tools/anvil-manage-server

@ -541,6 +541,10 @@ Parameters;
This is the UUID of the job to update. If it isn't set, but C<< jobs::job_uuid >> is set, it will be used. If that is also not set, This is the UUID of the job to update. If it isn't set, but C<< jobs::job_uuid >> is set, it will be used. If that is also not set,
=head3 log_level (optional)
If set to a numeric level, the job's message will also be logged. This is designed to simplify code as most job progress messages will also want to be logged.
=head3 message (optional) =head3 message (optional)
If set, this message will be appended to C<< job_status >>. If set to 'C<< clear >>', previous records will be removed. If set, this message will be appended to C<< job_status >>. If set to 'C<< clear >>', previous records will be removed.
@ -551,10 +555,26 @@ NOTE: This is in the format C<< <key>[,!!<variable_name1>!<variable_value1>[,...
If set, this is used for the C<< job_picked_up_by >> column. If it isn't set, the process ID of the caller is used. If set, this is used for the C<< job_picked_up_by >> column. If it isn't set, the process ID of the caller is used.
=head3 print (optional, default '1')
If C<< log_level >> is set, this can be set to C<< 1 >> to print the log entry to STDOUT, or C<< 0 >> to not.
=head3 priority (optional)
If C<< log_level >> is set, this can be set to the priority to use when logging (see C<< Alert->entry >>).
=head3 progress (required) =head3 progress (required)
This is a number to set the current progress to. This is a number to set the current progress to.
=head3 secure (optional, default '0')
If C<< log_level >> is set, this can be set to C<< 1 >> to indicate that it contains sensitive data, like a password.
=head3 variables (optional)
This can be set as a hash reference containing key / variable pairs to inject into the message key. the C<< variable => value >> pairs will be appended to the C<< message >> key automatically. This is meant to simplify when an alert is also being longed, or when a large number of variables are being injected into the string.
=cut =cut
sub update_progress sub update_progress
{ {
@ -565,16 +585,32 @@ sub update_progress
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Job->update_progress()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Job->update_progress()" }});
my $job_uuid = defined $parameter->{job_uuid} ? $parameter->{job_uuid} : ""; my $job_uuid = defined $parameter->{job_uuid} ? $parameter->{job_uuid} : "";
my $log_level = defined $parameter->{log_level} ? $parameter->{log_level} : "";
my $message = defined $parameter->{message} ? $parameter->{message} : ""; my $message = defined $parameter->{message} ? $parameter->{message} : "";
my $picked_up_by = defined $parameter->{picked_up_by} ? $parameter->{picked_up_by} : ""; my $picked_up_by = defined $parameter->{picked_up_by} ? $parameter->{picked_up_by} : "";
my $print = defined $parameter->{'print'} ? $parameter->{'print'} : 1;
my $priority = defined $parameter->{priority} ? $parameter->{priority} : "";
my $progress = defined $parameter->{progress} ? $parameter->{progress} : ""; my $progress = defined $parameter->{progress} ? $parameter->{progress} : "";
my $secure = defined $parameter->{secure} ? $parameter->{secure} : "";
my $variables = defined $parameter->{variables} ? $parameter->{variables} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
job_uuid => $job_uuid,
picked_up_by => $picked_up_by, picked_up_by => $picked_up_by,
'print' => $print,
progress => $progress, progress => $progress,
log_level => $log_level,
message => $message, message => $message,
job_uuid => $job_uuid, variables => $variables,
secure => $secure,
}}); }});
# Log before anything else, in case we abort the job update.
if (($message ne "clear") && ($log_level =~ /^\d+$/))
{
# Log this message.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $log_level, 'print' => $print, secure => $secure, priority => $priority, key => $message, variables => $variables});
}
if ($picked_up_by eq "") if ($picked_up_by eq "")
{ {
$picked_up_by = $$; $picked_up_by = $$;
@ -618,6 +654,16 @@ sub update_progress
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::last_update" => $anvil->data->{sys}{last_update} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::last_update" => $anvil->data->{sys}{last_update} }});
} }
# Add variables to the message, if required
if (ref($variables) eq "HASH")
{
foreach my $variable (sort {$a cmp $b} keys %{$variables})
{
my $value = defined $variables->{$variable} ? $variables->{$variable} : "undefined:".$variable;
$message .= ",!!".$variable."!".$value."!!";
}
}
# Get the current job_status and append this new one. # Get the current job_status and append this new one.
my $job_picked_up_at = 0; my $job_picked_up_at = 0;
my $job_status = ""; my $job_status = "";

@ -293,7 +293,7 @@ sub interactive_question
$anvil->data->{target_server}{anvil_dr1_host_name} = $anvil->data->{hosts}{host_uuid}{$dr1_host_uuid}{host_name};; $anvil->data->{target_server}{anvil_dr1_host_name} = $anvil->data->{hosts}{host_uuid}{$dr1_host_uuid}{host_name};;
} }
### Pull out details pf the server. ### Pull out details of the server.
# How much RAM are we using and how much is configured? # How much RAM are we using and how much is configured?
$anvil->data->{target_server}{server_ram_in_use} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_ram_in_use}; $anvil->data->{target_server}{server_ram_in_use} = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_ram_in_use};
$anvil->data->{target_server}{server_host_uuid} = $server_host_uuid; $anvil->data->{target_server}{server_host_uuid} = $server_host_uuid;
@ -421,7 +421,6 @@ sub interactive_question
# Do we know or can we find the Anvil! UUID? # Do we know or can we find the Anvil! UUID?
$anvil->data->{target_server}{anvil_uuid} = $anvil->data->{switches}{'anvil-uuid'} ? $anvil->data->{switches}{'anvil-uuid'} : ""; $anvil->data->{target_server}{anvil_uuid} = $anvil->data->{switches}{'anvil-uuid'} ? $anvil->data->{switches}{'anvil-uuid'} : "";
$anvil->data->{target_server}{anvil_name} = $anvil->data->{switches}{'anvil-name'} ? $anvil->data->{switches}{'anvil-name'} : ""; $anvil->data->{target_server}{anvil_name} = $anvil->data->{switches}{'anvil-name'} ? $anvil->data->{switches}{'anvil-name'} : "";
if ((not $anvil->data->{target_server}{anvil_uuid}) && (not $anvil->data->{target_server}{anvil_name})) if ((not $anvil->data->{target_server}{anvil_uuid}) && (not $anvil->data->{target_server}{anvil_name}))
{ {
# Nothing given. Is this host a node, perhaps? # Nothing given. Is this host a node, perhaps?
@ -440,8 +439,15 @@ sub interactive_question
} }
elsif (not $anvil->data->{target_server}{anvil_uuid}) elsif (not $anvil->data->{target_server}{anvil_uuid})
{ {
# We have a name, get the UUID.
$anvil->data->{target_server}{anvil_uuid} = $anvil->Cluster->get_anvil_uuid({anvil_name => $anvil->data->{target_server}{anvil_name}}); $anvil->data->{target_server}{anvil_uuid} = $anvil->Cluster->get_anvil_uuid({anvil_name => $anvil->data->{target_server}{anvil_name}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "target_server::anvil_uuid" => $anvil->data->{target_server}{anvil_uuid} }});
# If the name is bad, error out.
if (not $anvil->data->{target_server}{anvil_uuid})
{
}
} }
elsif (not $anvil->data->{target_server}{anvil_name}) elsif (not $anvil->data->{target_server}{anvil_name})
{ {

Loading…
Cancel
Save