diff --git a/lib/App/Netdisco/DB/Result/Admin.pm b/lib/App/Netdisco/DB/Result/Admin.pm index 85f75dec..cc5daa54 100644 --- a/lib/App/Netdisco/DB/Result/Admin.pm +++ b/lib/App/Netdisco/DB/Result/Admin.pm @@ -58,14 +58,14 @@ __PACKAGE__->set_primary_key("job"); =head1 RELATIONSHIPS -=head2 device_skips( $backend?, $max_deferrals? ) +=head2 device_skips( $backend?, $max_deferrals?, $retry_after? ) Retuns the set of C entries which apply to this job. They match the device IP, current backend, and job action. You probably want to use the ResultSet method C which completes this -query with a C host and C parameters (or sensible -defaults). +query with a C host, C, and C parameters +(or sensible defaults). =cut @@ -77,9 +77,13 @@ __PACKAGE__->has_many( device_skips => 'App::Netdisco::DB::Result::DeviceSkip', "$args->{foreign_alias}.device" => { -ident => "$args->{self_alias}.device" }, -or => [ - { "$args->{foreign_alias}.actionset" - => { '@>' => \"string_to_array($args->{self_alias}.action,'')" } }, - { "$args->{foreign_alias}.deferrals" => { '>=' => \'?' } }, + "$args->{foreign_alias}.actionset" + => { '@>' => \"string_to_array($args->{self_alias}.action,'')" }, + -and => [ + "$args->{foreign_alias}.deferrals" => { '>=' => \'?' }, + "$args->{foreign_alias}.last_defer" => + { '>', \'(LOCALTIMESTAMP - ?::interval)' }, + ], ], }; }, diff --git a/lib/App/Netdisco/DB/ResultSet/Admin.pm b/lib/App/Netdisco/DB/ResultSet/Admin.pm index 9e730b5a..bed194b1 100644 --- a/lib/App/Netdisco/DB/ResultSet/Admin.pm +++ b/lib/App/Netdisco/DB/ResultSet/Admin.pm @@ -12,29 +12,26 @@ __PACKAGE__->load_components(qw/ =head1 ADDITIONAL METHODS -=head2 skipped +=head2 skipped( $backend?, $max_deferrals?, $retry_after? ) Retuns a correlated subquery for the set of C entries that apply to some jobs. They match the device IP, current backend, and job action. -Pass the C FQDN (or the current host will be used as a default), and -the C (option disabled if 0/undef value is passed). +Pass the C FQDN (or the current host will be used as a default), the +C (option disabled if 0/undef value is passed), and +C when devices will be retried once (default 7 days). =cut sub skipped { - my ($rs, $backend, $max_deferrals) = @_; + my ($rs, $backend, $max_deferrals, $retry) = @_; $backend ||= (hostfqdn || 'localhost'); $max_deferrals ||= 10_000_000; # not really 'disabled' + $retry ||= '7 days'; - return $rs->correlate('device_skips')->search({ - -or => [ - last_defer => undef, - last_defer => { '<=', \q{(LOCALTIMESTAMP - INTERVAL '7 days')} }, - ], - },{ + return $rs->correlate('device_skips')->search(undef,{ # NOTE: bind param list order is significant - bind => [[deferrals => $max_deferrals], [backend => $backend]], + bind => [[deferrals => $max_deferrals], [last_defer => $retry], [backend => $backend]], }); } diff --git a/lib/App/Netdisco/JobQueue/PostgreSQL.pm b/lib/App/Netdisco/JobQueue/PostgreSQL.pm index 984383f1..67dd4837 100644 --- a/lib/App/Netdisco/JobQueue/PostgreSQL.pm +++ b/lib/App/Netdisco/JobQueue/PostgreSQL.pm @@ -44,7 +44,8 @@ sub _getsome { my $rs = $jobs->search({ status => 'queued', device => { '-not_in' => - $jobs->skipped($fqdn, setting('workers')->{'max_deferrals'}) + $jobs->skipped($fqdn, setting('workers')->{'max_deferrals'}, + setting('workers')->{'retry_after'}) ->columns('device')->as_query }, %$where, }, { order_by => 'random()', rows => $num_slots }); diff --git a/lib/App/Netdisco/Manual/Configuration.pod b/lib/App/Netdisco/Manual/Configuration.pod index e8f30434..fe537c6a 100644 --- a/lib/App/Netdisco/Manual/Configuration.pod +++ b/lib/App/Netdisco/Manual/Configuration.pod @@ -1307,6 +1307,7 @@ Value: Settings Tree. Default: sleep_time: 1 min_runtime: 0 max_deferrals: 10 + retry_after: '7 days' Control the activity of the backend daemon with this configuration setting. @@ -1329,6 +1330,9 @@ before the device is no longer polled. The setting and counters are local to each poller backend. To reset device counters, restart the backend daemon. To disable this feature configure the setting with a value of zero. +C is the time when each job is retried once, even when +permanently deferred. The default is each job retried once per week. + =head3 C Value: Settings Tree. Default: None. diff --git a/share/config.yml b/share/config.yml index cf0c6803..5e1856a1 100644 --- a/share/config.yml +++ b/share/config.yml @@ -207,6 +207,7 @@ workers: sleep_time: 1 min_runtime: 0 max_deferrals: 10 + retry_after: '7 days' queue: PostgreSQL dns: