()
| 22 | // const connectionDetails = { redis: new ioredis() }; |
| 23 | |
| 24 | async function boot() { |
| 25 | // ////////////// |
| 26 | // DEFINE JOBS // |
| 27 | // ////////////// |
| 28 | |
| 29 | const blockingSleep = function (naptime) { |
| 30 | const now = new Date(); |
| 31 | const startingMSeconds = now.getTime(); |
| 32 | let sleeping = true; |
| 33 | let alarm; |
| 34 | while (sleeping) { |
| 35 | alarm = new Date(); |
| 36 | const alarmMSeconds = alarm.getTime(); |
| 37 | if (alarmMSeconds - startingMSeconds > naptime) { |
| 38 | sleeping = false; |
| 39 | } |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | const jobs = { |
| 44 | slowSleepJob: { |
| 45 | plugins: [], |
| 46 | pluginOptions: {}, |
| 47 | perform: async () => { |
| 48 | const start = new Date().getTime(); |
| 49 | await new Promise((resolve) => { |
| 50 | setTimeout(resolve, 1000); |
| 51 | }); |
| 52 | return new Date().getTime() - start; |
| 53 | }, |
| 54 | }, |
| 55 | slowCPUJob: { |
| 56 | plugins: [], |
| 57 | pluginOptions: {}, |
| 58 | perform: async () => { |
| 59 | const start = new Date().getTime(); |
| 60 | blockingSleep(1000); |
| 61 | return new Date().getTime() - start; |
| 62 | }, |
| 63 | }, |
| 64 | }; |
| 65 | |
| 66 | // //////////////// |
| 67 | // ENQUEUE TASKS // |
| 68 | // //////////////// |
| 69 | |
| 70 | const queue = new Queue({ connection: connectionDetails }, jobs); |
| 71 | await queue.connect(); |
| 72 | let i = 0; |
| 73 | while (i < 10) { |
| 74 | await queue.enqueue("slowQueue", "slowCPUJob", []); |
| 75 | i++; |
| 76 | } |
| 77 | |
| 78 | i = 0; |
| 79 | while (i < 100) { |
| 80 | await queue.enqueue("slowQueue", "slowSleepJob", []); |
| 81 | i++; |
no test coverage detected