Skip to content

Commit f4f0bec

Browse files
authored
Support for job override (applicable fields: due, priority, data)
1 parent 62ea7bb commit f4f0bec

File tree

1 file changed

+37
-3
lines changed
  • package/server/imports/actions/add

1 file changed

+37
-3
lines changed

package/server/imports/actions/add/index.js

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var add = function () {
3030
arguments: input.arguments,
3131
})
3232

33+
3334
if (doc) blockAdd = true
3435
}
3536

@@ -45,9 +46,42 @@ var add = function () {
4546
// 3. Generate job document
4647
var jobDoc = Utilities.helpers.generateJobDoc(input);
4748

48-
// 4. Insert the job document into the database
49-
var jobId = Utilities.collection.insert(jobDoc);
49+
// 4. Insert the job document into the database OR update it
50+
var jobId;
51+
52+
if (input.config && input.config.override) {
53+
var doc = Utilities.collection.findOne({
54+
name: input.name,
55+
arguments: input.arguments,
56+
})
57+
58+
if (doc) {
59+
var initDate = jobDoc.created || new Date;
60+
61+
jobId = Utilities.collection.update(doc._id, {
62+
$set: {
63+
due: initDate,
64+
priority: jobDoc.priority,
65+
updated: jobDoc.created,
66+
data: jobDoc.data,
67+
},
68+
$push: {
69+
history: {
70+
date: initDate,
71+
state: "pending",
72+
serverId: Utilities.config.getServerId(),
73+
result: "Jobs/JobOveride"
74+
}
75+
}
76+
});
5077

78+
} else {
79+
jobId = Utilities.collection.insert(jobDoc);
80+
}
81+
} else {
82+
jobId = Utilities.collection.insert(jobDoc);
83+
}
84+
5185
// 5. Simulate the document (this might save us a database request in some places)
5286
if (jobId) {
5387
result = jobDoc;
@@ -65,4 +99,4 @@ var add = function () {
6599
return result;
66100
}
67101

68-
export { add }
102+
export { add }

0 commit comments

Comments
 (0)