« blib/lib/App/Netdisco/DB/ResultSet/AccessControlListName.pm
↑ Summary
blib/lib/App/Netdisco/DB/ResultSet/DeviceBrowser.pm »
| 1 | package App::Netdisco::DB::ResultSet::Admin; | ||
| 2 | use base 'App::Netdisco::DB::ResultSet'; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use 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 | |||
| 15 | Returns a correlated subquery for the set of C<device_skip> entries that apply | ||
| 16 | to some jobs. They match the device IP, current backend, and job action. | ||
| 17 | |||
| 18 | Pass the C<backend> FQDN (or the current host will be used as a default), the | ||
| 19 | C<max_deferrals> (option disabled if 0/undef value is passed), and | ||
| 20 | C<retry_after> when devices will be retried once (disabled if 0/undef passed). | ||
| 21 | |||
| 22 | =cut | ||
| 23 | |||
| 24 | sub 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 | |||
| 38 | This is a modifier for any C<search()> (including the helpers below) which | ||
| 39 | will 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 | =item duration | ||
| 50 | |||
| 51 | =back | ||
| 52 | |||
| 53 | =cut | ||
| 54 | |||
| 55 | sub with_times { | ||
| 56 | my ($rs, $cond, $attrs) = @_; | ||
| 57 | |||
| 58 | return $rs | ||
| 59 | ->search_rs($cond, $attrs) | ||
| 60 | ->search({}, | ||
| 61 | { | ||
| 62 | '+columns' => { | ||
| 63 | entered_stamp => \"to_char(entered, 'YYYY-MM-DD HH24:MI:SS')", | ||
| 64 | started_stamp => \"to_char(started, 'YYYY-MM-DD HH24:MI:SS')", | ||
| 65 | finished_stamp => \"to_char(finished, 'YYYY-MM-DD HH24:MI:SS')", | ||
| 66 | duration => \"justify_interval(extract(epoch FROM (finished - started)) * interval '1 second')", | ||
| 67 | }, | ||
| 68 | }); | ||
| 69 | } | ||
| 70 | |||
| 71 | 1; |