From 8d5911d43a51d6b1f1e1e7612f339d3f674273f8 Mon Sep 17 00:00:00 2001 From: Cole Rogers Date: Fri, 22 Sep 2023 11:24:14 -0400 Subject: [PATCH 1/4] fix retry in event triggers --- src/v2/providers/alerts/alerts.ts | 2 +- src/v2/providers/database.ts | 2 +- src/v2/providers/eventarc.ts | 2 +- src/v2/providers/firestore.ts | 2 +- src/v2/providers/pubsub.ts | 1 + src/v2/providers/remoteConfig.ts | 2 +- src/v2/providers/storage.ts | 2 +- src/v2/providers/tasks.ts | 1 + src/v2/providers/testLab.ts | 2 +- 9 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/v2/providers/alerts/alerts.ts b/src/v2/providers/alerts/alerts.ts index 5dbde4f74..383fb5eb7 100644 --- a/src/v2/providers/alerts/alerts.ts +++ b/src/v2/providers/alerts/alerts.ts @@ -249,7 +249,7 @@ export function getEndpointAnnotation( eventFilters: { alerttype: alertType, }, - retry: !!opts.retry, + retry: opts.retry || false, }, }; if (appId) { diff --git a/src/v2/providers/database.ts b/src/v2/providers/database.ts index c3318855c..d5ca1510a 100644 --- a/src/v2/providers/database.ts +++ b/src/v2/providers/database.ts @@ -446,7 +446,7 @@ export function makeEndpoint( eventType, eventFilters, eventFilterPathPatterns, - retry: false, + retry: opts.retry || false, }, }; } diff --git a/src/v2/providers/eventarc.ts b/src/v2/providers/eventarc.ts index 6d980e2f9..12dfbbb11 100644 --- a/src/v2/providers/eventarc.ts +++ b/src/v2/providers/eventarc.ts @@ -216,7 +216,7 @@ export function onCustomEventPublished( eventTrigger: { eventType: opts.eventType, eventFilters: {}, - retry: false, + retry: opts.retry || false, channel, }, }; diff --git a/src/v2/providers/firestore.ts b/src/v2/providers/firestore.ts index 619e089e3..4a2693b44 100644 --- a/src/v2/providers/firestore.ts +++ b/src/v2/providers/firestore.ts @@ -426,7 +426,7 @@ export function makeEndpoint( eventType, eventFilters, eventFilterPathPatterns, - retry: !!opts.retry, + retry: opts.retry || false, }, }; } diff --git a/src/v2/providers/pubsub.ts b/src/v2/providers/pubsub.ts index 19e368d41..6d48ae345 100644 --- a/src/v2/providers/pubsub.ts +++ b/src/v2/providers/pubsub.ts @@ -324,6 +324,7 @@ export function onMessagePublished( eventTrigger: { eventType: "google.cloud.pubsub.topic.v1.messagePublished", resource: `projects/${process.env.GCLOUD_PROJECT}/topics/${topic}`, + retry: opts.retry || false, }, }; }, diff --git a/src/v2/providers/remoteConfig.ts b/src/v2/providers/remoteConfig.ts index f6ff45172..92f94acf7 100644 --- a/src/v2/providers/remoteConfig.ts +++ b/src/v2/providers/remoteConfig.ts @@ -145,7 +145,7 @@ export function onConfigUpdated( eventTrigger: { eventType, eventFilters: {}, - retry: !!optsOrHandler.retry, + retry: optsOrHandler.retry || false, }, }; func.__endpoint = ep; diff --git a/src/v2/providers/storage.ts b/src/v2/providers/storage.ts index 451a257b5..9f831b1b1 100644 --- a/src/v2/providers/storage.ts +++ b/src/v2/providers/storage.ts @@ -603,7 +603,7 @@ export function onOperation( eventTrigger: { eventType, eventFilters: { bucket }, - retry: false, + retry: opts.retry || false, }, }; copyIfPresent(endpoint.eventTrigger, opts, "retry", "retry"); diff --git a/src/v2/providers/tasks.ts b/src/v2/providers/tasks.ts index 795939e1b..5967cef49 100644 --- a/src/v2/providers/tasks.ts +++ b/src/v2/providers/tasks.ts @@ -281,6 +281,7 @@ export function onTaskDispatched( convertInvoker ); convertIfPresent(func.__endpoint.taskQueueTrigger, opts, "invoker", "invoker", convertInvoker); + copyIfPresent(func.__endpoint.taskQueueTrigger, opts, "retry", "retry") func.__requiredAPIs = [ { diff --git a/src/v2/providers/testLab.ts b/src/v2/providers/testLab.ts index 0283a0280..a3bdc328f 100644 --- a/src/v2/providers/testLab.ts +++ b/src/v2/providers/testLab.ts @@ -206,7 +206,7 @@ export function onTestMatrixCompleted( eventTrigger: { eventType, eventFilters: {}, - retry: !!optsOrHandler.retry, + retry: optsOrHandler.retry || false, }, }; func.__endpoint = ep; From 5acf3048654260f57aa7adbd1c547b8bc9984439 Mon Sep 17 00:00:00 2001 From: Cole Rogers Date: Fri, 22 Sep 2023 11:25:47 -0400 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 1 + src/v2/providers/tasks.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 767a26aeb..01445e66b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ - Remove HTTP server shutdown message. (#1457) - Add features to task queue functions. (#1423) - Add traces to V2 Firestore trigger logs. (#1440) +- Fix retry in event triggered functions. (#1463) diff --git a/src/v2/providers/tasks.ts b/src/v2/providers/tasks.ts index 5967cef49..310485eca 100644 --- a/src/v2/providers/tasks.ts +++ b/src/v2/providers/tasks.ts @@ -281,7 +281,7 @@ export function onTaskDispatched( convertInvoker ); convertIfPresent(func.__endpoint.taskQueueTrigger, opts, "invoker", "invoker", convertInvoker); - copyIfPresent(func.__endpoint.taskQueueTrigger, opts, "retry", "retry") + copyIfPresent(func.__endpoint.taskQueueTrigger, opts, "retry", "retry"); func.__requiredAPIs = [ { From ad23582452ee698c8bbb18a3ad0dc520a634256c Mon Sep 17 00:00:00 2001 From: Cole Rogers Date: Fri, 22 Sep 2023 11:55:49 -0400 Subject: [PATCH 3/4] fix tests --- src/v2/providers/pubsub.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/v2/providers/pubsub.ts b/src/v2/providers/pubsub.ts index 6d48ae345..7ee5b48a3 100644 --- a/src/v2/providers/pubsub.ts +++ b/src/v2/providers/pubsub.ts @@ -324,7 +324,6 @@ export function onMessagePublished( eventTrigger: { eventType: "google.cloud.pubsub.topic.v1.messagePublished", resource: `projects/${process.env.GCLOUD_PROJECT}/topics/${topic}`, - retry: opts.retry || false, }, }; }, @@ -345,7 +344,7 @@ export function onMessagePublished( eventTrigger: { eventType: "google.cloud.pubsub.topic.v1.messagePublished", eventFilters: { topic }, - retry: false, + retry: opts.retry || false, }, }; copyIfPresent(endpoint.eventTrigger, opts, "retry", "retry"); From df1f36243251f2f87fb2a20cd6161ffa3db0b2ae Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Fri, 23 Aug 2024 11:30:47 -0700 Subject: [PATCH 4/4] Use nullish coalescing instea of logical or. --- src/v2/providers/alerts/alerts.ts | 2 +- src/v2/providers/database.ts | 2 +- src/v2/providers/eventarc.ts | 2 +- src/v2/providers/firestore.ts | 2 +- src/v2/providers/pubsub.ts | 2 +- src/v2/providers/remoteConfig.ts | 2 +- src/v2/providers/storage.ts | 2 +- src/v2/providers/testLab.ts | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/v2/providers/alerts/alerts.ts b/src/v2/providers/alerts/alerts.ts index 435efae38..7355e81a9 100644 --- a/src/v2/providers/alerts/alerts.ts +++ b/src/v2/providers/alerts/alerts.ts @@ -250,7 +250,7 @@ export function getEndpointAnnotation( eventFilters: { alerttype: alertType, }, - retry: opts.retry || false, + retry: opts.retry ?? false, }, }; if (appId) { diff --git a/src/v2/providers/database.ts b/src/v2/providers/database.ts index bbdbb5d08..8bccbc59b 100644 --- a/src/v2/providers/database.ts +++ b/src/v2/providers/database.ts @@ -447,7 +447,7 @@ export function makeEndpoint( eventType, eventFilters, eventFilterPathPatterns, - retry: opts.retry || false, + retry: opts.retry ?? false, }, }; } diff --git a/src/v2/providers/eventarc.ts b/src/v2/providers/eventarc.ts index d681885a7..34981f18a 100644 --- a/src/v2/providers/eventarc.ts +++ b/src/v2/providers/eventarc.ts @@ -217,7 +217,7 @@ export function onCustomEventPublished( eventTrigger: { eventType: opts.eventType, eventFilters: {}, - retry: opts.retry || false, + retry: opts.retry ?? false, channel, }, }; diff --git a/src/v2/providers/firestore.ts b/src/v2/providers/firestore.ts index d14e67c2b..1adf1478d 100644 --- a/src/v2/providers/firestore.ts +++ b/src/v2/providers/firestore.ts @@ -685,7 +685,7 @@ export function makeEndpoint( eventType, eventFilters, eventFilterPathPatterns, - retry: opts.retry || false, + retry: opts.retry ?? false, }, }; } diff --git a/src/v2/providers/pubsub.ts b/src/v2/providers/pubsub.ts index 75dc98f83..67a1b7126 100644 --- a/src/v2/providers/pubsub.ts +++ b/src/v2/providers/pubsub.ts @@ -345,7 +345,7 @@ export function onMessagePublished( eventTrigger: { eventType: "google.cloud.pubsub.topic.v1.messagePublished", eventFilters: { topic }, - retry: opts.retry || false, + retry: opts.retry ?? false, }, }; copyIfPresent(endpoint.eventTrigger, opts, "retry", "retry"); diff --git a/src/v2/providers/remoteConfig.ts b/src/v2/providers/remoteConfig.ts index 11f3392c7..a168dff1c 100644 --- a/src/v2/providers/remoteConfig.ts +++ b/src/v2/providers/remoteConfig.ts @@ -149,7 +149,7 @@ export function onConfigUpdated( eventTrigger: { eventType, eventFilters: {}, - retry: optsOrHandler.retry || false, + retry: optsOrHandler.retry ?? false, }, }; func.__endpoint = ep; diff --git a/src/v2/providers/storage.ts b/src/v2/providers/storage.ts index 7ffa56e30..2a2583d53 100644 --- a/src/v2/providers/storage.ts +++ b/src/v2/providers/storage.ts @@ -624,7 +624,7 @@ export function onOperation( eventTrigger: { eventType, eventFilters: { bucket }, - retry: opts.retry || false, + retry: opts.retry ?? false, }, }; copyIfPresent(endpoint.eventTrigger, opts, "retry", "retry"); diff --git a/src/v2/providers/testLab.ts b/src/v2/providers/testLab.ts index 931359f1f..3b4e5a3c1 100644 --- a/src/v2/providers/testLab.ts +++ b/src/v2/providers/testLab.ts @@ -207,7 +207,7 @@ export function onTestMatrixCompleted( eventTrigger: { eventType, eventFilters: {}, - retry: optsOrHandler.retry || false, + retry: optsOrHandler.retry ?? false, }, }; func.__endpoint = ep;