Created
June 27, 2022 19:39
-
-
Save thakursaurabh1998/912d28e5065cc561483b29985557dc76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Poll { | |
/** | |
* @typedef options | |
* @property {number} interval Interval between each poll in `seconds` | |
* @property {number} maxPollCount Max number of times to poll | |
* | |
* @param {options} options | |
* @param {(Object) => Promise<boolean>} pollingFunction | |
* @param {QueueClientInterface} queueClient | |
*/ | |
constructor({ interval, maxPollCount }, pollingFunction, queueClient, logger = console) { | |
this.logger = logger; | |
this.interval = interval; | |
this.queueClient = queueClient; | |
this.maxPollCount = maxPollCount; | |
this.pollingFunction = pollingFunction; | |
// The DLQ pushes all the expired messages to the COLLECTOR_QUEUE | |
// and our consumer subscribes to this queue. | |
this.mq.listen('COLLECTOR_QUEUE', options); | |
this.mq.on('dequeue', (data) => { | |
this.fetchAndValidate(data); | |
}); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment