()
| 48 | } |
| 49 | |
| 50 | async function boot() { |
| 51 | // /////////////////////////// |
| 52 | // DEFINE YOUR WORKER TASKS // |
| 53 | // /////////////////////////// |
| 54 | |
| 55 | let jobsToComplete = 0; |
| 56 | |
| 57 | const jobs = { |
| 58 | jobby: { |
| 59 | plugins: [MyPlugin], |
| 60 | pluginOptions: { |
| 61 | MyPlugin: { messagePrefix: "[🤡🤡🤡]" }, |
| 62 | }, |
| 63 | perform: (a, b) => { |
| 64 | jobsToComplete--; |
| 65 | tryShutdown(); |
| 66 | }, |
| 67 | }, |
| 68 | }; |
| 69 | |
| 70 | // just a helper for this demo |
| 71 | async function tryShutdown() { |
| 72 | if (jobsToComplete === 0) { |
| 73 | await new Promise((resolve) => { |
| 74 | setTimeout(resolve, 500); |
| 75 | }); |
| 76 | await worker.end(); |
| 77 | process.exit(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // ///////////////// |
| 82 | // START A WORKER // |
| 83 | // ///////////////// |
| 84 | |
| 85 | const worker = new Worker( |
| 86 | { connection: connectionDetails, queues: ["default"] }, |
| 87 | jobs, |
| 88 | ); |
| 89 | await worker.connect(); |
| 90 | worker.start(); |
| 91 | |
| 92 | // ////////////////////// |
| 93 | // REGESTER FOR EVENTS // |
| 94 | // ////////////////////// |
| 95 | |
| 96 | worker.on("start", () => { |
| 97 | console.log("worker started"); |
| 98 | }); |
| 99 | worker.on("end", () => { |
| 100 | console.log("worker ended"); |
| 101 | }); |
| 102 | worker.on("cleaning_worker", (worker, pid) => { |
| 103 | console.log(`cleaning old worker ${worker}`); |
| 104 | }); |
| 105 | worker.on("poll", (queue) => { |
| 106 | console.log(`worker polling ${queue}`); |
| 107 | }); |
no test coverage detected