add internal worker plugin to set fqdn for cli actions

This commit is contained in:
Oliver Gorwits
2023-09-26 09:27:23 +01:00
parent 370d483c5a
commit a8db56fa8c

View File

@@ -0,0 +1,25 @@
package App::Netdisco::Worker::Plugin::Internal::BackendFQDN;
use Dancer ':syntax';
use App::Netdisco::Worker::Plugin;
use aliased 'App::Netdisco::Worker::Status';
use Net::Domain 'hostfqdn';
use Scalar::Util 'blessed';
register_worker({ phase => 'check', driver => 'direct' }, sub {
my ($job, $workerconf) = @_;
my $action = $job->action or return;
# if the job is running at CLI it may need a BACKEND setting
return unless scalar grep {$_ eq $action} @{ setting('deferrable_actions') }
and not setting('workers')->{'BACKEND'};
# this can take a few seconds - only do it once
info 'resolving backend hostname...';
setting('workers')->{'BACKEND'} ||= (hostfqdn || 'fqdn-undefined');
debug sprintf 'Backend identity set to %s', setting('workers')->{'BACKEND'};
});
true;