« blib/lib/App/Netdisco/Worker/Plugin/Hook/HTTP.pm
↑ Summary
blib/lib/App/Netdisco/Worker/Plugin/Internal/SNMPFastDiscover.pm »
| 1 | package App::Netdisco::Worker::Plugin::Internal::BackendFQDN; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use App::Netdisco::Worker::Plugin; | ||
| 5 | use aliased 'App::Netdisco::Worker::Status'; | ||
| 6 | |||
| 7 | use Net::Domain 'hostfqdn'; | ||
| 8 | use Scalar::Util 'blessed'; | ||
| 9 | |||
| 10 | register_worker({ phase => 'check', driver => 'direct' }, sub { | ||
| 11 | my ($job, $workerconf) = @_; | ||
| 12 | my $action = $job->action or return; | ||
| 13 | |||
| 14 | # if the job is running at CLI it may need a BACKEND setting | ||
| 15 | return unless scalar grep {$_ eq $action} @{ setting('deferrable_actions') } | ||
| 16 | and not setting('workers')->{'BACKEND'}; | ||
| 17 | |||
| 18 | # this can take a few seconds - only do it once | ||
| 19 | info 'resolving backend hostname...'; | ||
| 20 | setting('workers')->{'BACKEND'} ||= (hostfqdn || 'fqdn-undefined'); | ||
| 21 | |||
| 22 | debug sprintf 'Backend identity set to %s', setting('workers')->{'BACKEND'}; | ||
| 23 | }); | ||
| 24 | |||
| 25 | true; |