1package App::Netdisco::DB::ResultSet::Admin;
2use base 'App::Netdisco::DB::ResultSet';
3
4use strict;
5use warnings;
6
7__PACKAGE__->load_components(qw/
8  +App::Netdisco::DB::ExplicitLocking
9/);
10
11=head1 ADDITIONAL METHODS
12
13=head2 skipped( $backend?, $max_deferrals?, $retry_after? )
14
15Returns a correlated subquery for the set of C<device_skip> entries that apply
16to some jobs. They match the device IP, current backend, and job action.
17
18Pass the C<backend> FQDN (or the current host will be used as a default), the
19C<max_deferrals> (option disabled if 0/undef value is passed), and
20C<retry_after> when devices will be retried once (disabled if 0/undef passed).
21
22=cut
23
24sub skipped {
25  my ($rs, $backend, $max_deferrals, $retry) = @_;
26  $backend ||= 'fqdn-undefined';
27  $max_deferrals ||= (2**30); # not really 'disabled'
28  $retry ||= '100 years'; # not really 'disabled'
29
30  return $rs->correlate('device_skips')->search(undef,{
31    # NOTE: bind param list order is significant
32    bind => [[deferrals => $max_deferrals], [last_defer => $retry], [backend => $backend]],
33  });
34}
35
36=head2 with_times
37
38This is a modifier for any C<search()> (including the helpers below) which
39will add the following additional synthesized columns to the result set:
40
41=over 4
42
43=item entered_stamp
44
45=item started_stamp
46
47=item finished_stamp
48
49=back
50
51=cut
52
53sub with_times {
54  my ($rs, $cond, $attrs) = @_;
55
56  return $rs
57    ->search_rs($cond, $attrs)
58    ->search({},
59      {
60        '+columns' => {
61          entered_stamp => \"to_char(entered, 'YYYY-MM-DD HH24:MI')",
62          started_stamp => \"to_char(started, 'YYYY-MM-DD HH24:MI')",
63          finished_stamp => \"to_char(finished, 'YYYY-MM-DD HH24:MI')",
64        },
65      });
66}
67
681;
69