App-Netdisco
view release on metacpan or search on metacpan
lib/App/Netdisco/Backend/Job.pm view on Meta::CPAN
=head2 add_status
Passed an L<App::Netdisco::Worker::Status> will add it to this job's internal
status cache. Phase slot of the Status will be set to the current phase.
=cut
sub add_status {
my ($job, $status) = @_;
return unless ref $status eq 'App::Netdisco::Worker::Status';
$status->phase( $job->_current_phase || '' );
push @{ $job->_statuslist }, $status;
if ($status->log) {
debug GREEN, "\N{LEFTWARDS BLACK ARROW} ", BRIGHT_GREEN, '(', $status->status, ') ', GREEN, $status->log, RESET;
}
}
=head1 ADDITIONAL COLUMNS
Columns which exist in this class but are not in
L<App::Netdisco::DB::Result::Admin> class.
=head2 id
Alias for the C<job> column.
=cut
sub id { (shift)->job }
=head2 extra
Alias for the C<subaction> column.
=head2 only_namespace
Action command from the user can be an action name or the action name plus one
child namespace in the form: "C<action::child>". This slot stores the C<child>
component of the command so that C<action> is backwards compatible with
Netdisco.
=head2 job_priority
When selecting jobs from the database, some types of job are higher priority -
usually those submitted in the web interface by a user, and those making
changes (writing to) the device. This slot stores a number which is the
priority of the job and is used by L<MCE> when managing its job queue.
=cut
sub extra { (shift)->subaction }
=head2 params
Parses the C<subaction> field as JSON and returns a hashref of parameters.
Returns an empty hashref if subaction is empty or not a dictionary.
This is used by the discover job to override configuration, particularly
SNMP timers which are sensitive for new devices. It returns an empty hashref
when C<subaction> is used for direct data provided for ARP/MAC addresses.
If C<subaction> is a plain string, it is promoted to being the C<device_auth_tag_hint>
key's value in the returned hashref.
=cut
sub params {
my $job = shift;
return {} unless $job->subaction;
return try {
my $r = from_json($job->subaction);
ref $r eq 'HASH' ? $r : {}
} catch { {device_auth_tag_hint => $job->subaction} };
}
true;
( run in 1.033 second using v1.01-cache-2.11-cpan-bbcb1afb8fc )