@data-fair/lib-node 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/events-queue.js +19 -9
- package/package.json +1 -1
package/events-queue.js
CHANGED
|
@@ -28,13 +28,9 @@ export class EventsQueue {
|
|
|
28
28
|
async loop () {
|
|
29
29
|
while (!this.stopped) {
|
|
30
30
|
await new Promise(resolve => setTimeout(resolve, 3000))
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.currentDrainPromise = undefined
|
|
35
|
-
} catch (err) {
|
|
36
|
-
internalError('events-queue-drain', err)
|
|
37
|
-
}
|
|
31
|
+
this.currentDrainPromise = this.drain()
|
|
32
|
+
await this.currentDrainPromise
|
|
33
|
+
this.currentDrainPromise = undefined
|
|
38
34
|
}
|
|
39
35
|
}
|
|
40
36
|
|
|
@@ -43,14 +39,28 @@ export class EventsQueue {
|
|
|
43
39
|
const events = this.eventsQueue
|
|
44
40
|
this.eventsQueue = []
|
|
45
41
|
debug('drain events', events.length)
|
|
46
|
-
|
|
42
|
+
try {
|
|
43
|
+
await axios.post(this.options().eventsUrl + '/api/events', events, { headers: { 'x-secret-key': this.options().eventsSecret } })
|
|
44
|
+
} catch (err) {
|
|
45
|
+
internalError('events-queue-push-event', err)
|
|
46
|
+
// retry later
|
|
47
|
+
if (err.status >= 500 && events.length < 1000) { this.eventsQueue = events.concat(this.eventsQueue) }
|
|
48
|
+
}
|
|
47
49
|
}
|
|
48
50
|
if (this.notificationsQueue.length) {
|
|
49
51
|
const notifications = this.notificationsQueue
|
|
50
52
|
this.notificationsQueue = []
|
|
51
53
|
debug('drain notifications', notifications.length)
|
|
52
54
|
for (const notification of notifications) {
|
|
53
|
-
|
|
55
|
+
try {
|
|
56
|
+
await axios.post(this.options().eventsUrl + '/api/notifications', notification, { headers: { 'x-secret-key': this.options().eventsSecret } })
|
|
57
|
+
} catch (err) {
|
|
58
|
+
internalError('events-queue-push-notif', err)
|
|
59
|
+
// retry later
|
|
60
|
+
if (err.status >= 500 && (notifications.length + this.notificationsQueue.length) < 1000) {
|
|
61
|
+
this.notificationsQueue.unshift()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
54
64
|
}
|
|
55
65
|
}
|
|
56
66
|
}
|