fix: ensures that delayed restock notifications are being sent (#881)

* fix: ensures that delayed restock notifications are being sent

* fix: default options to empty object

* fix: tests
This commit is contained in:
Sebastian Rindom authored and GitHub committed 2021-12-08 09:55:00 +01:00
1 parent 7d6fc5c9e1
commit 329767e279
4 files changed
+43 -29

No files matched your search

+7 -2
View File
@@ -148,9 +148,10 @@ class EventBusService {
* Calls all subscribers when an event occurs.
* @param {string} eventName - the name of the event to be process.
* @param {?any} data - the data to send to the subscriber.
* @param {?any} options - options to add the job with
* @return {BullJob} - the job from our queue
*/
async emit(eventName, data) {
async emit(eventName, data, options = {}) {
if (this.transactionManager_) {
const stagedJobRepository = this.transactionManager_.getCustomRepository(
this.stagedJobRepository_
@@ -163,7 +164,11 @@ class EventBusService {
return stagedJobRepository.save(created)
} else {
this.queue_.add({ eventName, data }, { removeOnComplete: true })
const opts = { removeOnComplete: true }
if (typeof options.delay === "number") {
opts.delay = options.delay
}
this.queue_.add({ eventName, data }, opts)
}
}