my $id = $job->id;
get_logger->debug("Taking job $id...");
my $daemon = hostname . ":$$";
- $job->update({daemon => $daemon});
- #if (set_job_daemon $job, hostname . ":$$") {
- if (1) {
+ $job->update({daemon => $daemon}, {where => {daemon => undef}})->discard_changes;
+ if ($job->daemon eq $daemon) {
get_logger->debug("Succesfully taken job $id");
process_job $job;
get_logger->debug("Job $id done");
} else {
- get_logger->debug("Job $id already taken");
+ get_logger->debug("Job $id already taken by " . $job->daemon);
}
}