From f13bd3e987ce012c153a547a2d022fa860a65903 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 25 May 2024 16:22:32 +0200 Subject: [PATCH] events-node: try to recreate subscription if it is cleaned up during polling Signed-off-by: Patrik Oldsberg --- .../src/api/DefaultEventsService.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/events-node/src/api/DefaultEventsService.ts b/plugins/events-node/src/api/DefaultEventsService.ts index 86083edeb2..74e37100e0 100644 --- a/plugins/events-node/src/api/DefaultEventsService.ts +++ b/plugins/events-node/src/api/DefaultEventsService.ts @@ -182,11 +182,12 @@ class PluginEventsService implements EventsService { throw await ResponseError.fromResponse(res); } - this.#startPolling(subscriptionId, options.onEvent); + this.#startPolling(subscriptionId, options.topics, options.onEvent); } #startPolling( subscriptionId: string, + topics: string[], onEvent: EventsServiceSubscribeOptions['onEvent'], ) { let backoffMs = POLL_BACKOFF_START_MS; @@ -208,6 +209,21 @@ class PluginEventsService implements EventsService { ); if (!res.ok) { + if (res.status === 404) { + this.logger.info( + `Polling event subscription resulted in a 404, recreating subscription`, + ); + const putRes = await this.client.putSubscription( + { + path: { subscriptionId }, + body: { topics }, + }, + { token }, + ); + if (!putRes.ok) { + throw await ResponseError.fromResponse(res); + } + } throw await ResponseError.fromResponse(res); } backoffMs = POLL_BACKOFF_START_MS;