From bb15abce58e3fb6a88552d4a230daf8080462923 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Sat, 12 Aug 2023 19:51:05 +0100 Subject: [PATCH] allow deferrable_actions exceptions to device deferrals --- lib/App/Netdisco/JobQueue/PostgreSQL.pm | 9 ++++++++- .../Netdisco/Worker/Plugin/Internal/SNMPFastDiscover.pm | 4 ++-- lib/App/Netdisco/Worker/Plugin/Snapshot.pm | 2 +- lib/App/Netdisco/Worker/Status.pm | 8 ++++---- share/config.yml | 3 +++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/App/Netdisco/JobQueue/PostgreSQL.pm b/lib/App/Netdisco/JobQueue/PostgreSQL.pm index 33d4b83a..42912516 100644 --- a/lib/App/Netdisco/JobQueue/PostgreSQL.pm +++ b/lib/App/Netdisco/JobQueue/PostgreSQL.pm @@ -236,9 +236,16 @@ sub jq_defer { # seeing as defer is only triggered by an SNMP connect failure, this # behaviour seems reasonable, to me (or desirable, perhaps). + # the deferrable_actions setting exists as a workaround to this behaviour + # should it be needed by any action (that is, per-device action but + # do not increment deferrals count and simply try to run again). + try { schema(vars->{'tenant'})->txn_do(sub { - if ($job->device) { + if ($job->device + and not scalar grep { $job->action eq $_ } + @{ setting('deferrable_actions') || [] }) { + schema(vars->{'tenant'})->resultset('DeviceSkip')->find_or_create({ backend => setting('workers')->{'BACKEND'}, device => $job->device, },{ key => 'device_skip_pkey' })->increment_deferrals; diff --git a/lib/App/Netdisco/Worker/Plugin/Internal/SNMPFastDiscover.pm b/lib/App/Netdisco/Worker/Plugin/Internal/SNMPFastDiscover.pm index a44028b5..b04a4e27 100644 --- a/lib/App/Netdisco/Worker/Plugin/Internal/SNMPFastDiscover.pm +++ b/lib/App/Netdisco/Worker/Plugin/Internal/SNMPFastDiscover.pm @@ -14,10 +14,10 @@ register_worker({ phase => 'check', driver => 'direct' }, sub { and (not blessed $job->device or not $job->device->in_storage)) { config->{'snmp_try_slow_connect'} = false; - return Status->info("running with fast SNMP timeouts for initial discover"); + debug "running with fast SNMP timeouts for initial discover"; } - return Status->info("running with configured SNMP timeouts"); + debug "running with configured SNMP timeouts"; }); true; diff --git a/lib/App/Netdisco/Worker/Plugin/Snapshot.pm b/lib/App/Netdisco/Worker/Plugin/Snapshot.pm index 5afb8267..a712a4b8 100644 --- a/lib/App/Netdisco/Worker/Plugin/Snapshot.pm +++ b/lib/App/Netdisco/Worker/Plugin/Snapshot.pm @@ -22,7 +22,7 @@ register_worker({ phase => 'check' }, sub { return Status->error('Missing device (-d).') unless defined shift->device; - return Status->info("snapshot skipped: please run a loadmibs job first") + return Status->defer("snapshot skipped: please run a loadmibs job first") unless schema('netdisco')->resultset('SNMPObject')->count(); return Status->done('Snapshot is able to run'); diff --git a/lib/App/Netdisco/Worker/Status.pm b/lib/App/Netdisco/Worker/Status.pm index 1a7f277f..8abdfbae 100644 --- a/lib/App/Netdisco/Worker/Status.pm +++ b/lib/App/Netdisco/Worker/Status.pm @@ -67,10 +67,10 @@ sub _make_new { return $new; } -sub done { shift->_make_new('done', @_) } -sub info { shift->_make_new('info', @_) } -sub defer { shift->_make_new('defer', @_) } -sub error { shift->_make_new('error', @_) } +sub done { shift->_make_new('done', @_) } # <- jq_complete +sub info { shift->_make_new('info', @_) } # <- jq_complete +sub defer { shift->_make_new('defer', @_) } # <- jq_defer +sub error { shift->_make_new('error', @_) } # <- jq_complete =head2 is_ok diff --git a/share/config.yml b/share/config.yml index 2ee4b80f..6fdd2858 100644 --- a/share/config.yml +++ b/share/config.yml @@ -572,6 +572,9 @@ driver_priority: cli: 200 snmp: 100 +deferrable_actions: + - 'snapshot' + # --------------- # GraphViz Export # ---------------