Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Support replacing existing jobs
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
Michael Klishin committed May 2, 2013
1 parent f71b8de commit fab6093
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -889,14 +889,8 @@ protected void storeTrigger(OperableTrigger newTrigger, ObjectId jobId, boolean
protected ObjectId storeJobInMongo(JobDetail newJob, boolean replaceExisting) throws ObjectAlreadyExistsException {
JobKey key = newJob.getKey();

BasicDBObject job = keyToDBObject(key);

if (replaceExisting) {
DBObject result = jobCollection.findOne(job);
if (result != null) {
result = job;
}
}
BasicDBObject keyDbo = keyToDBObject(key);
BasicDBObject job = keyToDBObject(key);

job.put(JOB_KEY_NAME, key.getName());
job.put(JOB_KEY_GROUP, key.getGroup());
Expand All @@ -906,7 +900,11 @@ protected ObjectId storeJobInMongo(JobDetail newJob, boolean replaceExisting) th
job.putAll(newJob.getJobDataMap());

try {
jobCollection.insert(job);
if (replaceExisting) {
jobCollection.update(keyDbo, job);
} else {
jobCollection.insert(job);
}

return (ObjectId) job.get("_id");
} catch (DuplicateKey e) {
Expand Down

0 comments on commit fab6093

Please sign in to comment.