|
1 | | -const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants'); |
| 1 | +const fs = require('fs'); |
| 2 | +const cp = require('child_process'); |
| 3 | + |
| 4 | +const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder, PENDING_QUEUS_FILE } = require('./constants'); |
2 | 5 | const { debug, batchAndPostEvents } = require('./helper'); |
3 | 6 |
|
4 | 7 | class RequestQueueHandler { |
@@ -51,17 +54,16 @@ class RequestQueueHandler { |
51 | 54 | shutdownSync = () => { |
52 | 55 | this.removeEventBatchPolling('REMOVING'); |
53 | 56 |
|
54 | | - require('fs').writeFileSync(require('path').join(__dirname, 'queue.json'), JSON.stringify(this.queue)); |
| 57 | + fs.writeFileSync(require('path').join(__dirname, PENDING_QUEUS_FILE), JSON.stringify(this.queue)); |
55 | 58 | this.queue = []; |
56 | | - require('child_process').spawnSync('node', [require('path').join(__dirname, 'shutdown.js'), require('path').join(__dirname, 'queue.json')], {stdio: 'inherit'}); |
| 59 | + cp.spawnSync('node', [require('path').join(__dirname, 'cleanupQueueSync.js'), require('path').join(__dirname, PENDING_QUEUS_FILE)], {stdio: 'inherit'}); |
57 | 60 | } |
58 | 61 |
|
59 | 62 | shutdown = async () => { |
60 | 63 | this.removeEventBatchPolling('REMOVING'); |
61 | 64 | while(this.queue.length > 0) { |
62 | 65 | const data = this.queue.slice(0,BATCH_SIZE); |
63 | 66 | this.queue.splice(0,BATCH_SIZE); |
64 | | - consoleHolder.log(this.queue.length + " the queue length "); |
65 | 67 | await batchAndPostEvents(this.eventUrl,'Shutdown-Queue',data); |
66 | 68 | } |
67 | 69 | } |
|
0 commit comments