From 1ad8ee1397c09a5cc42fd427ab238e013d9b5aa4 Mon Sep 17 00:00:00 2001 From: Will Murphy Date: Wed, 9 Nov 2022 10:40:43 -0600 Subject: [PATCH] set delivery request timeout, handle rejections in startDelivery --- deliveryWorker.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/deliveryWorker.js b/deliveryWorker.js index d463575..6a4bc64 100644 --- a/deliveryWorker.js +++ b/deliveryWorker.js @@ -28,6 +28,7 @@ const apex = ActivitypubExpress({ actorParam: 'actor', objectParam: 'id', itemsPerPage: 100, + requestTimeout: 500, routes }) @@ -37,16 +38,26 @@ client.connect() let resumeDeliveryTimer function deliver () { apex.startDelivery() - // delivery will stop if the queue empties, ensure it keeps running when new work is available - // no effect if called while already running - resumeDeliveryTimer = setTimeout(deliver, 5000) + .catch(err => { + console.error('Error starting delivery', err) + }) + .finally(() => { + // delivery will stop if the queue empties, ensure it keeps running when new work is available + // no effect if called while already running + resumeDeliveryTimer = setTimeout(deliver, 5000) + }) } deliver() onShutdown(async () => { clearTimeout(resumeDeliveryTimer) + apex.offlineMode = true // time for last delivery to finish (need to fix in apex) await new Promise(resolve => setTimeout(resolve, 3000)) await client.close() console.log('Guppe delivery worker closed') }) }) + .catch(err => { + console.error('Error starting delivery worker', err) + process.exit(1) + })