Skip to content

Commit 1253ca1

Browse files
authored
feat: add support for event_trigger_retry (#216)
1 parent 726b4f7 commit 1253ca1

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

.github/workflows/integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ jobs:
219219
source_dir: './tests/test-node-func/'
220220
event_trigger_type: 'providers/cloud.pubsub/eventTypes/topic.publish'
221221
event_trigger_resource: '${{ secrets.DEPLOY_CF_EVENT_PUBSUB_TOPIC }}'
222+
event_trigger_retry: true
222223
env_vars_file: './tests/env-var-files/test.good.yaml'
223224
build_environment_variables: 'FOO=bar, ZIP=zap'
224225
build_environment_variables_file: './tests/env-var-files/test.good.yaml'

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ steps:
9595

9696
- `event_trigger_service`: (Optional) The hostname of the service that should be observed.
9797

98+
- `event_trigger_retry`: (Optional) If true, the event will be retried if the
99+
function returns a failure. The default value is false. Note this applies to
100+
function invocation from events, not the deployment itself.
101+
98102
- `deploy_timeout`: (Optional) The function deployment timeout in seconds. Defaults to 300.
99103

100104
- `build_worker_pool`: (Optional) Name of the Cloud Build Custom Worker Pool

action.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ inputs:
134134
The hostname of the service that should be observed.
135135
required: false
136136

137+
event_trigger_retry:
138+
description: |-
139+
If true, the event will be retried if the function returns a failure.
140+
default: false
141+
required: false
142+
137143
deploy_timeout:
138144
description: |-
139145
The function deployment timeout in seconds.

src/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ export type EventTrigger = {
125125
eventType: string;
126126
resource: string;
127127
service?: string;
128+
failurePolicy?: FailurePolicy;
129+
};
130+
131+
export type FailurePolicy = {
132+
retry: Record<string, string>;
128133
};
129134

130135
export type CreateOptions = {

src/main.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import {
18+
getBooleanInput,
1819
getInput,
1920
info as logInfo,
2021
setFailed,
@@ -61,6 +62,7 @@ async function run(): Promise<void> {
6162
const eventTriggerType = presence(getInput('event_trigger_type'));
6263
const eventTriggerResource = presence(getInput('event_trigger_resource'));
6364
const eventTriggerService = presence(getInput('event_trigger_service'));
65+
const eventTriggerRetry = getBooleanInput('event_trigger_retry');
6466
const deployTimeout = presence(getInput('deploy_timeout'));
6567
const labels = parseKVString(getInput('labels'));
6668

@@ -154,9 +156,7 @@ async function run(): Promise<void> {
154156
labels: labels,
155157
maxInstances: maxInstances ? +maxInstances : undefined,
156158
minInstances: minInstances ? +minInstances : undefined,
157-
// network: network, // TODO: add support
158159
serviceAccountEmail: serviceAccountEmail,
159-
// sourceToken: sourceToken, // TODO: add support
160160
timeout: `${timeout}s`,
161161
vpcConnector: vpcConnector,
162162
vpcConnectorEgressSettings: vpcConnectorEgressSettings,
@@ -168,6 +168,14 @@ async function run(): Promise<void> {
168168
resource: eventTriggerResource,
169169
service: eventTriggerService,
170170
};
171+
172+
if (eventTriggerRetry) {
173+
cf.eventTrigger.failurePolicy = {
174+
// No, there's no value here. Retry is a oneof, and this is the
175+
// translation to javascript.
176+
retry: {},
177+
};
178+
}
171179
} else if (
172180
eventTriggerType ||
173181
eventTriggerResource ||

tests/client.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import { expect } from 'chai';
66
import os from 'os';
77
import path from 'path';
88
import crypto from 'crypto';
9-
import {
10-
CredentialBody,
11-
ExternalAccountClientOptions,
12-
} from 'google-auth-library';
139

1410
import { CloudFunctionsClient, CloudFunction } from '../src/client';
1511
import { parseServiceAccountKeyJSON, zipDir } from '../src/util';

0 commit comments

Comments
 (0)