set delivery request timeout, handle rejections in startDelivery
This commit is contained in:
parent
725346186b
commit
1ad8ee1397
1 changed files with 14 additions and 3 deletions
|
@ -28,6 +28,7 @@ const apex = ActivitypubExpress({
|
||||||
actorParam: 'actor',
|
actorParam: 'actor',
|
||||||
objectParam: 'id',
|
objectParam: 'id',
|
||||||
itemsPerPage: 100,
|
itemsPerPage: 100,
|
||||||
|
requestTimeout: 500,
|
||||||
routes
|
routes
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -37,16 +38,26 @@ client.connect()
|
||||||
let resumeDeliveryTimer
|
let resumeDeliveryTimer
|
||||||
function deliver () {
|
function deliver () {
|
||||||
apex.startDelivery()
|
apex.startDelivery()
|
||||||
// delivery will stop if the queue empties, ensure it keeps running when new work is available
|
.catch(err => {
|
||||||
// no effect if called while already running
|
console.error('Error starting delivery', err)
|
||||||
resumeDeliveryTimer = setTimeout(deliver, 5000)
|
})
|
||||||
|
.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()
|
deliver()
|
||||||
onShutdown(async () => {
|
onShutdown(async () => {
|
||||||
clearTimeout(resumeDeliveryTimer)
|
clearTimeout(resumeDeliveryTimer)
|
||||||
|
apex.offlineMode = true
|
||||||
// time for last delivery to finish (need to fix in apex)
|
// time for last delivery to finish (need to fix in apex)
|
||||||
await new Promise(resolve => setTimeout(resolve, 3000))
|
await new Promise(resolve => setTimeout(resolve, 3000))
|
||||||
await client.close()
|
await client.close()
|
||||||
console.log('Guppe delivery worker closed')
|
console.log('Guppe delivery worker closed')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error('Error starting delivery worker', err)
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue