-
-
Notifications
You must be signed in to change notification settings - Fork 151
/
performInline.ts
executable file
·63 lines (52 loc) · 1.26 KB
/
performInline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ts-node
import { Worker } from "../src";
/* In your projects:
import { Worker } from "node-resque";
*/
// ////////////////////////
// SET UP THE CONNECTION //
// ////////////////////////
const connectionDetails = {
pkg: "ioredis",
host: "127.0.0.1",
password: null,
port: 6379,
database: 0,
// namespace: 'resque',
// looping: true,
// options: {password: 'abc'},
};
async function boot() {
// ///////////////////////////
// DEFINE YOUR WORKER TASKS //
// ///////////////////////////
const jobs = {
add: {
plugins: [],
pluginOptions: {
JobLock: {},
},
perform: async (a, b) => {
await new Promise((resolve) => {
setTimeout(resolve, 1000);
});
const answer = a + b;
return answer;
},
},
};
// //////////////////////////////
// BUILD A WORKER & WORK A JOB //
// //////////////////////////////
const worker = new Worker(
{ connection: connectionDetails, queues: ["math", "otherQueue"] },
jobs,
);
await worker.connect();
let result = await worker.performInline("add", [1, 2]);
console.log("Result: " + result);
result = await worker.performInline("add", [5, 8]);
console.log("Result: " + result);
process.exit();
}
boot();