Skip to content

Commit

Permalink
feat: add support for event_trigger_retry (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Dec 8, 2021
1 parent 726b4f7 commit 1253ca1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ jobs:
source_dir: './tests/test-node-func/'
event_trigger_type: 'providers/cloud.pubsub/eventTypes/topic.publish'
event_trigger_resource: '${{ secrets.DEPLOY_CF_EVENT_PUBSUB_TOPIC }}'
event_trigger_retry: true
env_vars_file: './tests/env-var-files/test.good.yaml'
build_environment_variables: 'FOO=bar, ZIP=zap'
build_environment_variables_file: './tests/env-var-files/test.good.yaml'
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ steps:

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

- `event_trigger_retry`: (Optional) If true, the event will be retried if the
function returns a failure. The default value is false. Note this applies to
function invocation from events, not the deployment itself.

- `deploy_timeout`: (Optional) The function deployment timeout in seconds. Defaults to 300.

- `build_worker_pool`: (Optional) Name of the Cloud Build Custom Worker Pool
Expand Down
6 changes: 6 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ inputs:
The hostname of the service that should be observed.
required: false

event_trigger_retry:
description: |-
If true, the event will be retried if the function returns a failure.
default: false
required: false

deploy_timeout:
description: |-
The function deployment timeout in seconds.
Expand Down
5 changes: 5 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ export type EventTrigger = {
eventType: string;
resource: string;
service?: string;
failurePolicy?: FailurePolicy;
};

export type FailurePolicy = {
retry: Record<string, string>;
};

export type CreateOptions = {
Expand Down
12 changes: 10 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import {
getBooleanInput,
getInput,
info as logInfo,
setFailed,
Expand Down Expand Up @@ -61,6 +62,7 @@ async function run(): Promise<void> {
const eventTriggerType = presence(getInput('event_trigger_type'));
const eventTriggerResource = presence(getInput('event_trigger_resource'));
const eventTriggerService = presence(getInput('event_trigger_service'));
const eventTriggerRetry = getBooleanInput('event_trigger_retry');
const deployTimeout = presence(getInput('deploy_timeout'));
const labels = parseKVString(getInput('labels'));

Expand Down Expand Up @@ -154,9 +156,7 @@ async function run(): Promise<void> {
labels: labels,
maxInstances: maxInstances ? +maxInstances : undefined,
minInstances: minInstances ? +minInstances : undefined,
// network: network, // TODO: add support
serviceAccountEmail: serviceAccountEmail,
// sourceToken: sourceToken, // TODO: add support
timeout: `${timeout}s`,
vpcConnector: vpcConnector,
vpcConnectorEgressSettings: vpcConnectorEgressSettings,
Expand All @@ -168,6 +168,14 @@ async function run(): Promise<void> {
resource: eventTriggerResource,
service: eventTriggerService,
};

if (eventTriggerRetry) {
cf.eventTrigger.failurePolicy = {
// No, there's no value here. Retry is a oneof, and this is the
// translation to javascript.
retry: {},
};
}
} else if (
eventTriggerType ||
eventTriggerResource ||
Expand Down
4 changes: 0 additions & 4 deletions tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { expect } from 'chai';
import os from 'os';
import path from 'path';
import crypto from 'crypto';
import {
CredentialBody,
ExternalAccountClientOptions,
} from 'google-auth-library';

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

0 comments on commit 1253ca1

Please sign in to comment.