pass $job to the core worker

This commit is contained in:
Oliver Gorwits
2017-08-05 22:10:58 +01:00
parent d6523fe543
commit 685ec02108
2 changed files with 12 additions and 10 deletions

View File

@@ -26,7 +26,7 @@ register 'register_core_worker' => sub {
unless $workerconf->{hook} =~ m/^(?:before|on|after)$/;
my $worker = sub {
my $device = shift or return false;
my $job = shift or return false;
my $no = (exists $workerconf->{no} ? $workerconf->{no} : undef);
my $only = (exists $workerconf->{only} ? $workerconf->{only} : undef);
@@ -36,8 +36,10 @@ register 'register_core_worker' => sub {
# reduce device_auth by driver, plugin, worker's only/no
foreach my $stanza (@userconf) {
next if $no and check_acl_no($device, $no);
next if $only and not check_acl_only($device, $only);
if (ref $job->device) {
next if $no and check_acl_no($job->device->ip, $no);
next if $only and not check_acl_only($job->device->ip, $only);
}
next if exists $stanza->{driver}
and (($stanza->{driver} || '') ne $workerconf->{driver});
push @newuserconf, $stanza;
@@ -51,7 +53,7 @@ register 'register_core_worker' => sub {
# run worker
my $happy = false;
try {
$code->($device, $workerconf);
$code->($job, $workerconf);
$happy = true;
}
catch { debug $_ };

View File

@@ -55,13 +55,13 @@ An explanation of the C<%workerconf> options is below. The C<$coderef> is the
main body of your worker. Your worker is run in a L<Try::Tiny> statement to
catch errors, and passed the following arguments:
$coderef->($device, $workerconf);
$coderef->($job, $workerconf);
The C<$device> is an instance of L<App::Netdisco::DB::Result::Device> (that
is, an object representation of a row in the database). Note that for early
discover phases this row may not yet exist in the database. The C<$workerconf>
hashref is the set of configuration parameters you used to declare the worker
(documented below).
The C<$job> is an instance of L<App::Netdisco::Backend::Job>. Note that this
class has a C<device> slot which may be filled, depending on the action, and
if the device is not yet discovered then the row will not yet be in storage.
The C<$workerconf> hashref is the set of configuration parameters you used
to declare the worker (documented below).
=head2 Package Naming Convention