()
| 21 | }; |
| 22 | |
| 23 | async function boot() { |
| 24 | // /////////////////////////// |
| 25 | // DEFINE YOUR WORKER TASKS // |
| 26 | // /////////////////////////// |
| 27 | |
| 28 | let jobsToComplete = 0; |
| 29 | |
| 30 | const jobs = { |
| 31 | brokenJob: { |
| 32 | plugins: [], |
| 33 | pluginOptions: {}, |
| 34 | perform: function (a, b) { |
| 35 | jobsToComplete--; |
| 36 | tryShutdown(); |
| 37 | |
| 38 | throw new Error("broken message from job"); |
| 39 | }, |
| 40 | }, |
| 41 | }; |
| 42 | |
| 43 | // just a helper for this demo |
| 44 | async function tryShutdown() { |
| 45 | if (jobsToComplete === 0) { |
| 46 | await new Promise((resolve) => { |
| 47 | setTimeout(resolve, 500); |
| 48 | }); |
| 49 | await worker.end(); |
| 50 | process.exit(); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // ///////////////// |
| 55 | // START A WORKER // |
| 56 | // ///////////////// |
| 57 | |
| 58 | const worker = new Worker( |
| 59 | { connection: connectionDetails, queues: ["default"] }, |
| 60 | jobs, |
| 61 | ); |
| 62 | await worker.connect(); |
| 63 | worker.start(); |
| 64 | |
| 65 | // ////////////////////// |
| 66 | // REGESTER FOR EVENTS // |
| 67 | // ////////////////////// |
| 68 | |
| 69 | worker.on("start", () => { |
| 70 | console.log("worker started"); |
| 71 | }); |
| 72 | worker.on("end", () => { |
| 73 | console.log("worker ended"); |
| 74 | }); |
| 75 | worker.on("cleaning_worker", (worker, pid) => { |
| 76 | console.log(`cleaning old worker ${worker}`); |
| 77 | }); |
| 78 | worker.on("poll", (queue) => { |
| 79 | console.log(`worker polling ${queue}`); |
| 80 | }); |
no test coverage detected