remove any duplicate jobs when locking

This commit is contained in:
Oliver Gorwits
2014-05-17 20:31:18 +01:00
parent d4b5e4e6cd
commit 8077e3de9d

View File

@@ -59,9 +59,9 @@ sub jq_queued {
my $job_type = shift;
return schema('netdisco')->resultset('Admin')->search({
device => { '!=' => undef},
action => $job_type,
status => { -like => 'queued%' },
device => { '!=' => undef},
action => $job_type,
status => { -like => 'queued%' },
})->get_column('device')->all;
}
@@ -109,6 +109,15 @@ sub jq_lock {
schema('netdisco')->resultset('Admin')
->find($job->id, {for => 'update'})
->update({ status => "queued-$fqdn" });
# remove any duplicate jobs, needed because we have race conditions
# when queueing jobs of a type for all devices
schema('netdisco')->resultset('Admin')->search({
device => $job->device,
port => $job->port,
action => $job->action,
subaction => $job->subaction,
}, {for => 'update'})->delete();
});
$happy = true;
};