Skip to content

Commit 7709ab9

Browse files
committed
4.3.0
1 parent abb7e48 commit 7709ab9

File tree

8 files changed

+34
-62
lines changed

8 files changed

+34
-62
lines changed

.DS_Store

0 Bytes
Binary file not shown.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ const add = function () {
1313
if (input.config && input.config.singular) {
1414
const doc = Utilities.collection.findOne({
1515
name: input.name,
16-
arguments: input.arguments,
17-
state: {
18-
$in: ["pending", "failure"]
19-
}
16+
arguments: input.arguments
2017
})
2118

2219
if (doc) blockAdd = true
@@ -26,7 +23,10 @@ const add = function () {
2623
if (input.config && input.config.unique) {
2724
const doc = Utilities.collection.findOne({
2825
name: input.name,
29-
arguments: input.arguments
26+
arguments: input.arguments,
27+
state: {
28+
$in: ["pending", "failure"]
29+
}
3030
})
3131

3232
if (doc) blockAdd = true

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const execute = async function (job, callback) {
77
message: "Job is not valid or not found, or is already resolved:"
88
});
99

10-
console.log(`Jobs.execute`, jobDoc.name, jobDoc._id, jobDoc.due)
11-
1210
if (typeof jobDoc === "object") {
1311
if (typeof Utilities.registry.data[jobDoc.name]) {
1412
const result = await process(jobDoc, callback);
Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Promise } from "meteor/promise"
12
import { Utilities } from "../../utilities"
23
import { toolbelt } from "./toolbelt.js"
34
import { reschedule } from "../reschedule/"
@@ -9,51 +10,27 @@ const process = async function (doc, callback) {
910
// 3- Capture the result (if any)
1011

1112
const Toolbelt = new toolbelt(doc);
12-
const jobFunc = Utilities.registry.data[doc.name];
13-
const isAsync = jobFunc.constructor.name === "AsyncFunction";
1413

15-
if (isAsync) {
16-
await jobFunc.apply(Toolbelt, doc.arguments)
17-
.catch(function (error) {
18-
const failure = Toolbelt.failure(error);
19-
20-
Utilities.logger(`Job failed to run due to code error: ${doc.name}`)
21-
console.log(error);
14+
try {
15+
const res = Utilities.registry.data[doc.name].apply(Toolbelt, doc.arguments);
16+
const jobResult = Promise.await(Promise.resolve(res));
17+
const resolution = Toolbelt.checkForResolution(jobResult);
2218

23-
if (typeof callback === "function") {
24-
return callback(error, undefined);
25-
}
26-
})
27-
.then(function (jobResult) {
28-
const resolution = Toolbelt.checkForResolution(jobResult);
29-
30-
if (typeof callback === "function") {
31-
return callback(undefined, jobResult);
32-
} else {
33-
return jobResult;
34-
}
35-
});
36-
} else {
37-
try {
38-
const jobResult = jobFunc.apply(Toolbelt, doc.arguments);
39-
const resolution = Toolbelt.checkForResolution(jobResult);
40-
41-
if (typeof callback === "function") {
42-
return callback(undefined, jobResult);
43-
} else {
44-
return jobResult;
45-
}
46-
} catch (error) {
47-
const failure = Toolbelt.failure(error.stack);
48-
49-
Utilities.logger(`Job failed to run due to code error: ${doc.name}`)
50-
console.log(error);
51-
52-
if (typeof callback === "function") {
53-
return callback(error, undefined);
54-
}
19+
if (typeof callback === "function") {
20+
return callback(undefined, jobResult);
21+
} else {
22+
return jobResult;
23+
}
24+
} catch (error) {
25+
const failure = Toolbelt.failure(error.stack);
26+
27+
Utilities.logger(`Job failed to run due to code error: ${doc.name}`)
28+
console.log(error);
29+
30+
if (typeof callback === "function") {
31+
return callback(error, undefined);
5532
}
56-
}
33+
}
5734
}
5835

5936
export { process }

package/server/imports/operator/manager/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { queue } from "../queue"
22
import { Utilities } from "../../utilities/"
33

4-
let debugMode = true;
4+
let debugMode = false;
55

66
const manager = {}
77

@@ -48,4 +48,4 @@ manager.isAvailable = function (name) {
4848
return manager.queues[name].available;
4949
}
5050

51-
export { manager, start, stop }
51+
export { manager }

package/server/imports/operator/queue/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let debugMode = false;
88
const queue = function (name, state = "failure") {
99
this.name = name;
1010
this.state = "failure";
11-
this.interval = null;
11+
this.interval = false;
1212
this.available = true;
1313
this.previouslyRan = "this needs to be defined for the Mongo query :P";
1414
}

package/server/imports/startup/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import { Operator } from "../operator/"
88
Meteor.startup(function () {
99
Utilities.start();
1010
Operator.start();
11-
12-
Meteor.setTimeout(function () {
13-
if (Utilities.config.autoStart) {
14-
Meteor.setTimeout(function () {
15-
console.log("=> Started jobs queue")
16-
Operator.manager.start();
17-
}, Utilities.config.startupDelay);
18-
}
19-
}, 3000)
11+
12+
if (Utilities.config.autoStart) {
13+
Operator.manager.start();
14+
console.log("=> Started jobs queue")
15+
} else {
16+
console.log("=> Steve Jobs: auto start is disabled")
17+
}
2018
});

package/server/imports/utilities/config/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const config = {
66
autoRetry: true,
77
started: false,
88
interval: 3000,
9-
startupDelay: 1 * 1000,
109
maxWait: 5 * 60 * 1000,
1110
disableDevelopmentMode: false,
1211
remoteCollection: undefined,

0 commit comments

Comments
 (0)