MCPcopy Create free account
hub / github.com/actionhero/node-resque / boot

Function boot

examples/example-mock.ts:10–171  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8import * as RedisMock from "ioredis-mock";
9
10async function boot() {
11 // ////////////////////////
12 // SET UP THE CONNECTION //
13 // ////////////////////////
14
15 // for ioredis-mock, we need to re-use a shared connection
16 // setting "pkg" is important!
17 const connectionDetails = { redis: new RedisMock(), pkg: "ioredis-mock" };
18
19 // ///////////////////////////
20 // DEFINE YOUR WORKER TASKS //
21 // ///////////////////////////
22
23 let jobsToComplete = 0;
24
25 const jobs = {
26 add: {
27 plugins: [Plugins.JobLock],
28 pluginOptions: {
29 JobLock: {},
30 },
31 perform: async (a, b) => {
32 await new Promise((resolve) => {
33 setTimeout(resolve, 1000);
34 });
35 jobsToComplete--;
36 tryShutdown();
37
38 const answer = a + b;
39 return answer;
40 },
41 },
42 subtract: {
43 perform: (a, b) => {
44 jobsToComplete--;
45 tryShutdown();
46
47 const answer = a - b;
48 return answer;
49 },
50 },
51 };
52
53 // just a helper for this demo
54 async function tryShutdown() {
55 if (jobsToComplete === 0) {
56 await new Promise((resolve) => {
57 setTimeout(resolve, 500);
58 });
59 await scheduler.end();
60 await worker.end();
61 process.exit();
62 }
63 }
64
65 // /////////////////
66 // START A WORKER //
67 // /////////////////

Callers 1

example-mock.tsFile · 0.70

Calls 11

connectMethod · 0.95
startMethod · 0.95
connectMethod · 0.95
startMethod · 0.95
onMethod · 0.95
onMethod · 0.95
onMethod · 0.95
connectMethod · 0.95
enqueueMethod · 0.95
enqueueInMethod · 0.95
tryShutdownFunction · 0.70

Tested by

no test coverage detected