Skip to content

Commit 8520daa

Browse files
harryadelBastienRodz
authored andcommitted
async migration
1 parent bb7c349 commit 8520daa

File tree

44 files changed

+79
-211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+79
-211
lines changed

package/package.js renamed to package.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ Package.onUse(function(api) {
1212
api.mainModule("server/api.js", "server");
1313
api.export(["Jobs", "JobsInternal"]);
1414
});
15+
16+
Package.onTest(function (api) {
17+
api.use('tinytest');
18+
api.use(['ecmascript', 'msavin:sjobs'], ['server']);
19+
api.use(["mongo", "random", "check"], "server");
20+
21+
api.addFiles([
22+
// "tests/basic.js",
23+
// "tests/internals.js",
24+
"tests/replication.js"
25+
])
26+
});

package/.DS_Store

-6 KB
Binary file not shown.

package/README.md

Lines changed: 0 additions & 149 deletions
This file was deleted.
File renamed without changes.

package/server/api.js renamed to server/api.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,31 +135,31 @@ Jobs.cancel = function (jobId) {
135135

136136
// Start or stop the queue - intended for debugging and/or single server deployments
137137

138-
Jobs.start = function (name) {
138+
Jobs.start = async function (name) {
139139
check(name, Match.OneOf(undefined, String, [String]))
140-
Operator.manager.start(name);
140+
return await Operator.manager.start(name);
141141
}
142142

143-
Jobs.stop = function (name) {
143+
Jobs.stop = async function (name) {
144144
check(name, Match.OneOf(undefined, String, [String]))
145-
Operator.manager.stop(name);
145+
return await Operator.manager.stop(name);
146146
}
147147

148148
// Get info on a job
149149

150-
Jobs.get = function (jobId) {
150+
Jobs.get = async function (jobId) {
151151
check(jobId, String);
152-
return Actions.get(jobId);
152+
return await Actions.get(jobId);
153153
}
154154

155155
// Run a job ahead of time
156156

157-
Jobs.execute = function (jobId, callback, force) {
157+
Jobs.execute = async function (jobId, callback, force) {
158158
check(jobId, String)
159159
check(force, Match.Optional(Boolean))
160160

161161
// 1. Get the job
162-
const doc = Utilities.collection.findOne({
162+
const doc = await Utilities.collection.findOneAsync({
163163
_id: jobId,
164164
state: {
165165
$nin: ["success", "cancelled"]
@@ -197,7 +197,7 @@ Jobs.execute = function (jobId, callback, force) {
197197

198198
// Reschedule a job
199199

200-
Jobs.reschedule = function (jobId, config) {
200+
Jobs.reschedule = async function (jobId, config) {
201201
check(jobId, String)
202202
if (config) check(config, {
203203
date: Match.Maybe(Date),
@@ -207,12 +207,12 @@ Jobs.reschedule = function (jobId, config) {
207207
callback: Match.Maybe(Function)
208208
})
209209

210-
return Actions.reschedule(jobId, config);
210+
return await Actions.reschedule(jobId, config);
211211
}
212212

213213
// Replicate a job to run it again later
214214

215-
Jobs.replicate = function (jobId, config) {
215+
Jobs.replicate = async function (jobId, config) {
216216
check(jobId, String)
217217
if (config) check(config, {
218218
date: Match.Maybe(Date),
@@ -222,26 +222,26 @@ Jobs.replicate = function (jobId, config) {
222222
priority: Match.Maybe(Number),
223223
})
224224

225-
return Actions.replicate(jobId, config);
225+
return await Actions.replicate(jobId, config);
226226
}
227227

228228
// Clear resolved jobs - or all of them
229229

230-
Jobs.clear = function (state, name, callback) {
230+
Jobs.clear = async function (state, name, callback) {
231231
check(state, Match.OneOf(undefined, String, [String]))
232232
check(name, Match.Optional(String))
233233
check(callback, Match.Optional(Function))
234234

235-
return Actions.clear(state, name, callback);
235+
return await Actions.clear(state, name, callback);
236236
}
237237

238238
// Remove the job
239239

240-
Jobs.remove = function (jobId, callback) {
240+
Jobs.remove = async function (jobId, callback) {
241241
check(jobId, String)
242242
check(callback, Match.Maybe(Function))
243243

244-
return Actions.remove(jobId, callback);
244+
return await Actions.remove(jobId, callback);
245245
}
246246

247247
// Expose the MongoDB collection
File renamed without changes.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const add = async function () {
4949
// 4. Insert the job document into the database OR update it
5050
let jobId;
5151

52-
if (input.config && input.config.override) {
52+
if (input.config && input.config.override) {
5353
const doc = await Utilities.collection.findOneAsync({
5454
name: input.name,
5555
arguments: input.arguments,
@@ -79,10 +79,10 @@ const add = async function () {
7979
});
8080

8181
} else {
82-
jobId = await Utilities.collection.insertAsync(jobDoc);
82+
jobId = await Utilities.collection.insertAsync(jobDoc);
8383
}
8484
} else {
85-
jobId = await Utilities.collection.insertAsync(jobDoc);
85+
jobId = await Utilities.collection.insertAsync(jobDoc);
8686
}
8787

8888
// 5. Simulate the document (this might save us a database request in some places)

package/server/imports/actions/clear/index.js renamed to server/imports/actions/clear/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const clear = async function (state, name, callback) {
2828
}
2929

3030
const result = await Utilities.collection.removeAsync(action)
31-
31+
3232
if (callback) {
3333
callback(undefined, result);
3434
}

0 commit comments

Comments
 (0)