Skip to content

Commit

Permalink
feat: adding support for failure policy
Browse files Browse the repository at this point in the history
following serverless#132
  • Loading branch information
EthanChouTW committed Jul 22, 2020
1 parent 7cd25ea commit 6404a47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package/lib/compileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ module.exports = {
const type = funcObject.events[0].event.eventType;
const path = funcObject.events[0].event.path; //eslint-disable-line
const resource = funcObject.events[0].event.resource;
const failurePolicy = funcObject.events[0].event.failurePolicy;

funcTemplate.properties.eventTrigger = {};
funcTemplate.properties.eventTrigger.eventType = type;
if (path) funcTemplate.properties.eventTrigger.path = path;
funcTemplate.properties.eventTrigger.resource = resource;
if (failurePolicy) funcTemplate.properties.eventTrigger.failurePolicy = failurePolicy;
}

this.serverless.service.provider.compiledConfigurationTemplate.resources.push(funcTemplate);
Expand Down
35 changes: 35 additions & 0 deletions package/lib/compileFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,20 @@ describe('CompileFunctions', () => {
},
],
},
func3: {
handler: 'func3',
events: [
{
event: {
eventType: 'foo',
resource: 'some-resource',
failurePolicy: {
retry: {},
},
},
},
],
},
};

const compiledResources = [
Expand Down Expand Up @@ -608,6 +622,27 @@ describe('CompileFunctions', () => {
labels: {},
},
},
{
type: 'gcp-types/cloudfunctions-v1:projects.locations.functions',
name: 'my-service-dev-func3',
properties: {
entryPoint: 'func3',
parent: 'projects/myProject/locations/us-central1',
runtime: 'nodejs8',
function: 'my-service-dev-func3',
availableMemoryMb: 256,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
eventTrigger: {
eventType: 'foo',
resource: 'some-resource',
failurePolicy: {
retry: {},
},
},
labels: {},
},
},
];

return googlePackage.compileFunctions().then(() => {
Expand Down

0 comments on commit 6404a47

Please sign in to comment.