Skip to content

Commit 885c6de

Browse files
committed
Fixed issues with variables not being accessed properly in toolbelt.js:
Ensured that uses of `doc` were initialized within their respective calling functions and set to `this.document`. Additionally, made it so that calls to `docId` were instead to `doc._id`. Removed function calls that had void return being set to variables in reschedule/index.js Made Operator a const so that it is more explicit as a variable for IDE parsing.
1 parent 7250e1e commit 885c6de

File tree

3 files changed

+58
-62
lines changed

3 files changed

+58
-62
lines changed

package/server/imports/actions/execute/toolbelt.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { Utilities } from "../../utilities"
22
import { Operator } from "../../operator"
3-
import { reschedule } from "../reschedule/"
3+
import { reschedule } from "../reschedule"
44
import { replicate } from "../replicate/"
55
import { remove } from "../remove/"
66

7-
var toolbelt = function (jobDoc) {
7+
let toolbelt = function (jobDoc) {
88
this.document = jobDoc;
9-
this.resolved = false;
9+
this.resolved = false;
1010

11-
this.set = function (key, value) {
11+
this.set = function (key, value) {
1212
check(key, String)
1313

14-
var docId = this.document._id;
15-
var patch = {}
14+
let docId = this.document._id;
15+
let patch = {}
1616
patch["data." + key] = value;
1717

1818
// first, update the document
19-
var update = Utilities.collection.update(docId, {
19+
let update = Utilities.collection.update(docId, {
2020
$set: patch
2121
})
2222

@@ -31,16 +31,16 @@ var toolbelt = function (jobDoc) {
3131

3232
this.get = function (key, getLatestFromDatabase) {
3333
check(key, String)
34-
var docId = this.document._id
34+
let docId = this.document._id
3535

3636

3737
if (getLatestFromDatabase) {
3838
// Get the latest doc
39-
doc = Utilities.collection.findOne(docId);
39+
let doc = Utilities.collection.findOne(docId);
4040

4141
// Update the cached doc with the fresh copy
4242
if (doc) {
43-
this.document = doc;
43+
this.document = doc;
4444
}
4545
}
4646

@@ -50,9 +50,9 @@ var toolbelt = function (jobDoc) {
5050
this.push = function (key, value) {
5151
check(key, String)
5252

53-
var docId = this.document._id;
53+
let docId = this.document._id;
5454

55-
var update = Utilities.collection.update(docId, {
55+
let update = Utilities.collection.update(docId, {
5656
$push: {
5757
["data." + key]: value
5858
}
@@ -64,9 +64,9 @@ var toolbelt = function (jobDoc) {
6464
this.pull = function (key, value) {
6565
check(key, String)
6666

67-
var docId = this.document._id;
67+
let docId = this.document._id;
6868

69-
var update = Utilities.collection.update(docId, {
69+
let update = Utilities.collection.update(docId, {
7070
$pull: {
7171
["data." + key]: value
7272
}
@@ -76,9 +76,9 @@ var toolbelt = function (jobDoc) {
7676
this.pullAll = function (key, value) {
7777
check(key, String)
7878

79-
var docId = this.document._id;
79+
let docId = this.document._id;
8080

81-
var update = Utilities.collection.update(docId, {
81+
let update = Utilities.collection.update(docId, {
8282
$pullAll: {
8383
["data." + key]: value
8484
}
@@ -90,9 +90,9 @@ var toolbelt = function (jobDoc) {
9090
check(value, Number)
9191
value = value || 1
9292

93-
var docId = this.document._id;
93+
let docId = this.document._id;
9494

95-
var update = Utilities.collection.update(docId, {
95+
let update = Utilities.collection.update(docId, {
9696
$inc: {
9797
["data." + key]: value
9898
}
@@ -104,9 +104,9 @@ var toolbelt = function (jobDoc) {
104104
check(value, Number)
105105
value = value || 1
106106

107-
var docId = this.document._id;
107+
let docId = this.document._id;
108108

109-
var update = Utilities.collection.update(docId, {
109+
let update = Utilities.collection.update(docId, {
110110
$dec: {
111111
["data." + key]: value
112112
}
@@ -118,22 +118,22 @@ var toolbelt = function (jobDoc) {
118118
check(value, Number)
119119
value = value || 1
120120

121-
var docId = this.document._id;
121+
let docId = this.document._id;
122122

123-
var update = Utilities.collection.update(docId, {
123+
let update = Utilities.collection.update(docId, {
124124
$addToSet: {
125125
["data." + key]: value
126126
}
127127
})
128128
}
129129

130130
this.success = function (result) {
131-
var docId = this.document._id;
131+
let docId = this.document._id;
132132

133-
var update = Utilities.collection.update(docId, {
133+
let update = Utilities.collection.update(docId, {
134134
$set: {
135135
state: "success",
136-
},
136+
},
137137
$push: {
138138
history: {
139139
date: new Date(),
@@ -150,14 +150,14 @@ var toolbelt = function (jobDoc) {
150150
}
151151

152152
this.failure = function (result) {
153-
var docId = this.document._id;
154-
var queueName = this.document.name;
153+
let docId = this.document._id;
154+
let queueName = this.document.name;
155155

156156
// Update the document
157-
var update = Utilities.collection.update(docId, {
157+
let update = Utilities.collection.update(docId, {
158158
$set: {
159159
state: "failure",
160-
},
160+
},
161161
$push: {
162162
history: {
163163
date: new Date(),
@@ -170,7 +170,7 @@ var toolbelt = function (jobDoc) {
170170

171171
// Stop the queue
172172
Utilities.logger([
173-
"Job has failed: " + queueName + ", " + docId,
173+
"Job has failed: " + queueName + ", " + docId,
174174
"Queue was stopped; please correct your job function and restart the server"
175175
]);
176176

@@ -182,44 +182,44 @@ var toolbelt = function (jobDoc) {
182182
}
183183

184184
this.reschedule = function (config) {
185-
var docId = this.document._id;
186-
var newDate = reschedule(docId, config);
185+
const doc = this.document;
186+
let newDate = reschedule(doc._id, config);
187187

188188
if (!newDate) {
189-
Utilities.logger(["Error rescheduling job: " + doc.name + "/" + docId, config]);
189+
Utilities.logger(["Error rescheduling job: " + doc.name + "/" + doc._id, config]);
190190
}
191191

192192
this.resolved = true;
193-
return newDate;
193+
return newDate;
194194
}
195195

196196
this.replicate = function (config) {
197-
var doc = this.document;
198-
var newCopy = replicate(doc, config)
197+
const doc = this.document;
198+
const newCopy = replicate(doc, config)
199199

200200
if (!newCopy) {
201-
Utilities.logger(["Error cloning job: " + doc.name + "/" + docId, config]);
201+
Utilities.logger(["Error cloning job: " + doc.name + "/" + doc._id, config]);
202202
}
203203

204204
return newCopy;
205205
}
206206

207207
this.remove = function () {
208-
var docId = this.document._id;
209-
var removeDoc = remove(docId)
208+
const doc = this.document;
209+
let removeDoc = remove(doc._id)
210210

211211
if (!removeDoc) {
212-
Utilities.logger(["Error removing job: " + doc.name + "/" + docId, config]);
212+
Utilities.logger(["Error removing job: " + doc.name + "/" + doc._id]);
213213
}
214214

215215
this.resolved = true;
216216
return removeDoc;
217217
}
218218

219219
this.clearHistory = function () {
220-
var docId = this.document._id;
220+
let docId = this.document._id;
221221

222-
var update = Utilities.collection.update(docId, {
222+
let update = Utilities.collection.update(docId, {
223223
$set: {
224224
history: [{
225225
date: new Date(),
@@ -233,12 +233,12 @@ var toolbelt = function (jobDoc) {
233233
}
234234

235235
this.checkForResolution = function (result) {
236-
var docId = this.document._id;
237-
var resolution = this.resolved;
236+
let docId = this.document._id;
237+
let resolution = this.resolved;
238238

239239

240240
if (!resolution) this.success(result)
241241
}
242242
}
243243

244-
export { toolbelt }
244+
export { toolbelt }
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Utilities } from "../../utilities"
22

3-
reschedule = function (job, config, callback) {
3+
function reschedule(job, config, callback) {
44
var error,
55
result,
66
jobDoc = Utilities.helpers.getJob(job, {
@@ -22,33 +22,29 @@ reschedule = function (job, config, callback) {
2222
}
2323

2424
// Second, set the priority, if any
25-
var determineNewPriority = function () {
26-
if (config && config.priority) {
27-
var val = Utilities.helpers.number(config.priority, "priority") || 0;
28-
dbUpdate.$set.priority = val;
29-
dbUpdate.$push.history.newPriority = val;
30-
}
31-
}();
25+
if (config && config.priority) {
26+
var val = Utilities.helpers.number(config.priority, "priority") || 0;
27+
dbUpdate.$set.priority = val;
28+
dbUpdate.$push.history.newPriority = val;
29+
}
3230

3331
// Third, create a new date, if any
34-
var newDueDate = function () {
35-
var val = Utilities.helpers.generateDueDate(config);
36-
dbUpdate.$set.due = val;
37-
dbUpdate.$push.history.newDue = val;
38-
}();
32+
var val = Utilities.helpers.generateDueDate(config);
33+
dbUpdate.$set.due = val;
34+
dbUpdate.$push.history.newDue = val;
3935

4036
// Finally, run the update
4137
result = Utilities.collection.update(jobDoc._id, dbUpdate)
4238
} else {
4339
error = true
4440
}
4541

46-
// and job finished
42+
// and job finished
4743
if (callback) {
4844
callback(error, result);
4945
}
5046

5147
return result;
5248
}
5349

54-
export { reschedule }
50+
export { reschedule }

package/server/imports/operator/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { queue } from "./queue/"
22
import { dominator } from "./dominator/"
33
import { manager } from "./manager/"
44

5-
Operator = {
5+
const Operator = {
66
dominator: dominator,
77
queue: queue,
88
manager: manager
@@ -12,4 +12,4 @@ Operator.start = function () {
1212
Operator.dominator.initialize();
1313
}
1414

15-
export { Operator }
15+
export { Operator }

0 commit comments

Comments
 (0)