pass $job to the core worker
This commit is contained in:
@@ -26,7 +26,7 @@ register 'register_core_worker' => sub {
|
|||||||
unless $workerconf->{hook} =~ m/^(?:before|on|after)$/;
|
unless $workerconf->{hook} =~ m/^(?:before|on|after)$/;
|
||||||
|
|
||||||
my $worker = sub {
|
my $worker = sub {
|
||||||
my $device = shift or return false;
|
my $job = shift or return false;
|
||||||
|
|
||||||
my $no = (exists $workerconf->{no} ? $workerconf->{no} : undef);
|
my $no = (exists $workerconf->{no} ? $workerconf->{no} : undef);
|
||||||
my $only = (exists $workerconf->{only} ? $workerconf->{only} : 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
|
# reduce device_auth by driver, plugin, worker's only/no
|
||||||
foreach my $stanza (@userconf) {
|
foreach my $stanza (@userconf) {
|
||||||
next if $no and check_acl_no($device, $no);
|
if (ref $job->device) {
|
||||||
next if $only and not check_acl_only($device, $only);
|
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}
|
next if exists $stanza->{driver}
|
||||||
and (($stanza->{driver} || '') ne $workerconf->{driver});
|
and (($stanza->{driver} || '') ne $workerconf->{driver});
|
||||||
push @newuserconf, $stanza;
|
push @newuserconf, $stanza;
|
||||||
@@ -51,7 +53,7 @@ register 'register_core_worker' => sub {
|
|||||||
# run worker
|
# run worker
|
||||||
my $happy = false;
|
my $happy = false;
|
||||||
try {
|
try {
|
||||||
$code->($device, $workerconf);
|
$code->($job, $workerconf);
|
||||||
$happy = true;
|
$happy = true;
|
||||||
}
|
}
|
||||||
catch { debug $_ };
|
catch { debug $_ };
|
||||||
|
|||||||
@@ -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
|
main body of your worker. Your worker is run in a L<Try::Tiny> statement to
|
||||||
catch errors, and passed the following arguments:
|
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
|
The C<$job> is an instance of L<App::Netdisco::Backend::Job>. Note that this
|
||||||
is, an object representation of a row in the database). Note that for early
|
class has a C<device> slot which may be filled, depending on the action, and
|
||||||
discover phases this row may not yet exist in the database. The C<$workerconf>
|
if the device is not yet discovered then the row will not yet be in storage.
|
||||||
hashref is the set of configuration parameters you used to declare the worker
|
The C<$workerconf> hashref is the set of configuration parameters you used
|
||||||
(documented below).
|
to declare the worker (documented below).
|
||||||
|
|
||||||
=head2 Package Naming Convention
|
=head2 Package Naming Convention
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user