increment deferrals field when job is deferred

This commit is contained in:
Oliver Gorwits
2017-05-23 08:58:57 +01:00
parent 88ae9c00ba
commit e7c22e7d11
2 changed files with 25 additions and 1 deletions

View File

@@ -18,6 +18,25 @@ __PACKAGE__->add_columns(
"skipover",
{ data_type => "boolean", is_nullable => 1, default_value => \'false' },
);
__PACKAGE__->set_primary_key("backend", "device", "action");
__PACKAGE__->add_unique_constraint(
device_skip_pkey => [qw/backend device action/]);
=head1 METHODS
=head2 increment_deferrals
Increments the C<deferrals> field in the row, only if the row is in storage.
There is a race in the update, but this is not worrying for now.
=cut
sub increment_deferrals {
my $row = shift;
return unless $row->in_storage;
return $row->update({ deferrals => ($row->deferrals + 1) });
}
1;

View File

@@ -189,11 +189,16 @@ sub jq_lock {
sub jq_defer {
my $job = shift;
my $fqdn = hostfqdn || 'localhost';
my $happy = false;
try {
# lock db row and update to show job is available
schema('netdisco')->txn_do(sub {
schema('netdisco')->resultset('DeviceSkip')->find_or_create({
backend => $fqdn, device => $job->device, action => $job->action,
},{ key => 'device_skip_pkey' })->increment_deferrals;
# lock db row and update to show job is available
schema('netdisco')->resultset('Admin')
->find($job->job, {for => 'update'})
->update({ status => 'queued', started => undef });