1use utf8; 2package App::Netdisco::DB::Result::DeviceSkip; 3 4use strict; 5use warnings; 6 7use List::MoreUtils (); 8 9use base 'App::Netdisco::DB::Result'; 10__PACKAGE__->table("device_skip"); 11__PACKAGE__->add_columns( 12 "backend", 13 { data_type => "text", is_nullable => 0 }, 14 "device", 15 { data_type => "inet", is_nullable => 0 }, 16 "actionset", 17 { data_type => "text[]", is_nullable => 1, default_value => \"'{}'::text[]" }, 18 "deferrals", 19 { data_type => "integer", is_nullable => 1, default_value => '0' }, 20 "last_defer", 21 { data_type => "timestamp", is_nullable => 1 }, 22); 23 24__PACKAGE__->set_primary_key("backend", "device"); 25 26__PACKAGE__->add_unique_constraint( 27 device_skip_pkey => [qw/backend device/]); 28 29=head1 METHODS 30 31=head2 increment_deferrals 32 33Increments the C<deferrals> field in the row, only if the row is in storage. 34There is a race in the update, but this is not worrying for now. 35 36=cut 37 38sub increment_deferrals { 39 my $row = shift; 40 return unless $row->in_storage; 41 return $row->update({ 42 deferrals => (($row->deferrals || 0) + 1), 43 last_defer => \'now()', 44 }); 45} 46 47=head2 add_to_actionset 48 49=cut 50 51sub add_to_actionset { 52 my ($row, @badactions) = @_; 53 return unless $row->in_storage; 54 return unless scalar @badactions; 55 return $row->update({ actionset => 56 [ sort (List::MoreUtils::uniq( @{ $row->actionset || [] }, @badactions )) ] 57 }); 58} 59 601; 61