increment deferrals field when job is deferred
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user