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
=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
the device IP, current backend, and job action.
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
defaults).
query with a C<backend> host, C<max_deferrals>, and C<retry_after> 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)' },
],
],
};
},

View File

@@ -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<device_skip> entries that apply
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
the C<max_deferrals> (option disabled if 0/undef value is passed).
Pass the C<backend> FQDN (or the current host will be used as a default), the
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
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]],
});
}