Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- Improve performance and reliability when deploying multiple 2nd gen functions using single builds. (#6376)
- Fixed an issue where `emulators:export` did not check if the target folder is empty. (#6313)
- Fixed an issue where retry could not be set for event triggered functions. (#6391)
- Fixed "Could not find the next executable" on Next.js deployments (#6372)
- Fixed issues caused by breaking changes in Next >=v13.5.0. (#6382)
18 changes: 14 additions & 4 deletions src/gcp/cloudfunctionsv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export type FunctionState = "ACTIVE" | "FAILED" | "DEPLOYING" | "DELETING" | "UN
// Values allowed for the operator field in EventFilter
export type EventFilterOperator = "match-path-pattern";

// Values allowed for the event trigger retry policy in case of a function's execution failure.
export type RetryPolicy =
| "RETRY_POLICY_UNSPECIFIED"
| "RETRY_POLICY_DO_NOT_RETRY"
| "RETRY_POLICY_RETRY";

/** Settings for building a container out of the customer source. */
export interface BuildConfig {
runtime: runtimes.Runtime;
Expand Down Expand Up @@ -140,6 +146,8 @@ export interface EventTrigger {
// to the defualt compute service account.
serviceAccountEmail?: string;

retryPolicy?: RetryPolicy;

// The name of the channel associated with the trigger in
// `projects/{project}/locations/{location}/channels/{channel}` format.
channel?: string;
Expand Down Expand Up @@ -542,6 +550,7 @@ export function functionFromEndpoint(endpoint: backend.Endpoint): InputCloudFunc
if (backend.isEventTriggered(endpoint)) {
gcfFunction.eventTrigger = {
eventType: endpoint.eventTrigger.eventType,
retryPolicy: "RETRY_POLICY_UNSPECIFIED",
};
if (gcfFunction.eventTrigger.eventType === PUBSUB_PUBLISH_EVENT) {
if (!endpoint.eventTrigger.eventFilters?.topic) {
Expand Down Expand Up @@ -579,9 +588,10 @@ export function functionFromEndpoint(endpoint: backend.Endpoint): InputCloudFunc
);
proto.copyIfPresent(gcfFunction.eventTrigger, endpoint.eventTrigger, "channel");

if (endpoint.eventTrigger.retry) {
logger.warn("Cannot set a retry policy on Cloud Function", endpoint.id);
}
endpoint.eventTrigger.retry
? (gcfFunction.eventTrigger.retryPolicy = "RETRY_POLICY_RETRY")
: (gcfFunction.eventTrigger!.retryPolicy = "RETRY_POLICY_DO_NOT_RETRY");

// By default, Functions Framework in GCFv2 opts to downcast incoming cloudevent messages to legacy formats.
// Since Firebase Functions SDK expects messages in cloudevent format, we set FUNCTION_SIGNATURE_TYPE to tell
// Functions Framework to disable downcast before passing the cloudevent message to function handler.
Expand Down Expand Up @@ -665,7 +675,7 @@ export function endpointFromFunction(gcfFunction: OutputCloudFunction): backend.
trigger = {
eventTrigger: {
eventType: gcfFunction.eventTrigger.eventType,
retry: false,
retry: gcfFunction.eventTrigger.retryPolicy === "RETRY_POLICY_RETRY" ? true : false,
},
};
if (Object.keys(eventFilters).length) {
Expand Down
5 changes: 4 additions & 1 deletion src/test/gcp/cloudfunctionsv2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe("cloudfunctionsv2", () => {
resource: "projects/p/regions/r/instances/i",
serviceName: "compute.googleapis.com",
},
retry: false,
retry: true,
channel: "projects/myproject/locations/us-wildwest11/channels/mychannel",
},
};
Expand All @@ -126,6 +126,7 @@ describe("cloudfunctionsv2", () => {
value: "compute.googleapis.com",
},
],
retryPolicy: "RETRY_POLICY_RETRY",
channel: "projects/myproject/locations/us-wildwest11/channels/mychannel",
},
serviceConfig: {
Expand Down Expand Up @@ -165,6 +166,7 @@ describe("cloudfunctionsv2", () => {
operator: "match-path-pattern",
},
],
retryPolicy: "RETRY_POLICY_DO_NOT_RETRY",
},
serviceConfig: {
...CLOUD_FUNCTION_V2.serviceConfig,
Expand Down Expand Up @@ -302,6 +304,7 @@ describe("cloudfunctionsv2", () => {
value: "pubsub.googleapis.com",
},
],
retryPolicy: "RETRY_POLICY_DO_NOT_RETRY",
},
serviceConfig: {
...CLOUD_FUNCTION_V2.serviceConfig,
Expand Down