retry jobs once per week

This commit is contained in:
Oliver Gorwits
2017-06-12 22:31:20 +01:00
parent 33454669e3
commit ef0d326287
5 changed files with 25 additions and 18 deletions

View File

@@ -58,14 +58,14 @@ __PACKAGE__->set_primary_key("job");
=head1 RELATIONSHIPS =head1 RELATIONSHIPS
=head2 device_skips( $backend?, $max_deferrals? ) =head2 device_skips( $backend?, $max_deferrals?, $retry_after? )
Retuns the set of C<device_skip> entries which apply to this job. They match Retuns the set of C<device_skip> entries which apply to this job. They match
the device IP, current backend, and job action. the device IP, current backend, and job action.
You probably want to use the ResultSet method C<skipped> which completes this You probably want to use the ResultSet method C<skipped> which completes this
query with a C<backend> host and C<max_deferrals> parameters (or sensible query with a C<backend> host, C<max_deferrals>, and C<retry_after> parameters
defaults). (or sensible defaults).
=cut =cut
@@ -77,9 +77,13 @@ __PACKAGE__->has_many( device_skips => 'App::Netdisco::DB::Result::DeviceSkip',
"$args->{foreign_alias}.device" "$args->{foreign_alias}.device"
=> { -ident => "$args->{self_alias}.device" }, => { -ident => "$args->{self_alias}.device" },
-or => [ -or => [
{ "$args->{foreign_alias}.actionset" "$args->{foreign_alias}.actionset"
=> { '@>' => \"string_to_array($args->{self_alias}.action,'')" } }, => { '@>' => \"string_to_array($args->{self_alias}.action,'')" },
{ "$args->{foreign_alias}.deferrals" => { '>=' => \'?' } }, -and => [
"$args->{foreign_alias}.deferrals" => { '>=' => \'?' },
"$args->{foreign_alias}.last_defer" =>
{ '>', \'(LOCALTIMESTAMP - ?::interval)' },
],
], ],
}; };
}, },

View File

@@ -12,29 +12,26 @@ __PACKAGE__->load_components(qw/
=head1 ADDITIONAL METHODS =head1 ADDITIONAL METHODS
=head2 skipped =head2 skipped( $backend?, $max_deferrals?, $retry_after? )
Retuns a correlated subquery for the set of C<device_skip> entries that apply Retuns a correlated subquery for the set of C<device_skip> entries that apply
to some jobs. They match the device IP, current backend, and job action. to some jobs. They match the device IP, current backend, and job action.
Pass the C<backend> FQDN (or the current host will be used as a default), and Pass the C<backend> FQDN (or the current host will be used as a default), the
the C<max_deferrals> (option disabled if 0/undef value is passed). C<max_deferrals> (option disabled if 0/undef value is passed), and
C<retry_after> when devices will be retried once (default 7 days).
=cut =cut
sub skipped { sub skipped {
my ($rs, $backend, $max_deferrals) = @_; my ($rs, $backend, $max_deferrals, $retry) = @_;
$backend ||= (hostfqdn || 'localhost'); $backend ||= (hostfqdn || 'localhost');
$max_deferrals ||= 10_000_000; # not really 'disabled' $max_deferrals ||= 10_000_000; # not really 'disabled'
$retry ||= '7 days';
return $rs->correlate('device_skips')->search({ return $rs->correlate('device_skips')->search(undef,{
-or => [
last_defer => undef,
last_defer => { '<=', \q{(LOCALTIMESTAMP - INTERVAL '7 days')} },
],
},{
# NOTE: bind param list order is significant # NOTE: bind param list order is significant
bind => [[deferrals => $max_deferrals], [backend => $backend]], bind => [[deferrals => $max_deferrals], [last_defer => $retry], [backend => $backend]],
}); });
} }

View File

@@ -44,7 +44,8 @@ sub _getsome {
my $rs = $jobs->search({ my $rs = $jobs->search({
status => 'queued', status => 'queued',
device => { '-not_in' => 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 }, ->columns('device')->as_query },
%$where, %$where,
}, { order_by => 'random()', rows => $num_slots }); }, { order_by => 'random()', rows => $num_slots });

View File

@@ -1307,6 +1307,7 @@ Value: Settings Tree. Default:
sleep_time: 1 sleep_time: 1
min_runtime: 0 min_runtime: 0
max_deferrals: 10 max_deferrals: 10
retry_after: '7 days'
Control the activity of the backend daemon with this configuration setting. 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 each poller backend. To reset device counters, restart the backend daemon. To
disable this feature configure the setting with a value of zero. disable this feature configure the setting with a value of zero.
C<retry_after> is the time when each job is retried once, even when
permanently deferred. The default is each job retried once per week.
=head3 C<schedule> =head3 C<schedule>
Value: Settings Tree. Default: None. Value: Settings Tree. Default: None.

View File

@@ -207,6 +207,7 @@ workers:
sleep_time: 1 sleep_time: 1
min_runtime: 0 min_runtime: 0
max_deferrals: 10 max_deferrals: 10
retry_after: '7 days'
queue: PostgreSQL queue: PostgreSQL
dns: dns: