[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying failure policies #482

Merged
merged 56 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
6a8e381
Define an interface for FailurePolicy
merlinnot Jun 21, 2019
282da1b
Extract functions config to avoid dependency cycles, assign failure p…
merlinnot Jun 21, 2019
33137a6
Add a changelog entry
merlinnot Jun 21, 2019
facd69c
Update dependencies, minor version bump
merlinnot Jun 21, 2019
819a564
Reformat
merlinnot Jun 21, 2019
f42584c
Fix a typo: allows -> allow
merlinnot Jun 21, 2019
0c554db
Avoid abbreviations to improve readability
merlinnot Jun 21, 2019
c633a78
Rename remaining Opts to Options
merlinnot Jun 24, 2019
568113c
Add tests for specifying failure policy
merlinnot Jun 24, 2019
993907f
Reformat
merlinnot Jun 24, 2019
acb761d
Merge branch 'master' into fix-issue-425
merlinnot Jun 25, 2019
b1344df
Merge branch 'master' into fix-issue-425
merlinnot Jun 25, 2019
a23beff
Merge branch 'master' into fix-issue-425
merlinnot Jul 2, 2019
3e46d65
Change format of an entry in the changelog
merlinnot Jul 3, 2019
b0ad579
Revert version bump
merlinnot Jul 3, 2019
6893b35
Extract configuration to break dependency cycle
merlinnot Jul 3, 2019
ae767a6
Merge branch 'master' into extract-config
merlinnot Jul 3, 2019
3fc81ff
Merge branch 'master' into extract-config
merlinnot Jul 3, 2019
f28e5bf
Add comments to Schedule and ScheduleRetryConfig
merlinnot Jul 3, 2019
22b6d0b
Stricten regions definition
merlinnot Jul 3, 2019
85d1329
Fix tests broken due to strict typings
merlinnot Jul 3, 2019
3ee8a0a
More strict types for regions - reverse order
merlinnot Jul 3, 2019
0cbe15a
Reformat
merlinnot Jul 3, 2019
a9b0929
Merge branch 'extract-config' into fix-issue-425
merlinnot Jul 3, 2019
61ebd4a
Merge branch 'master' into fix-issue-425
merlinnot Jul 3, 2019
a95e7de
Remove unused import
merlinnot Jul 3, 2019
2fced88
Merge branch 'master' into fix-issue-425
merlinnot Jul 9, 2019
3695897
Merge branch 'master' into fix-issue-425
merlinnot Jul 10, 2019
b1c6737
Conform with npm formatting
merlinnot Jul 10, 2019
b2c9b7f
Reintroduce unused variable to minimize diff size
merlinnot Jul 10, 2019
3a0dd5a
Import lodash using _ exclusively
merlinnot Jul 10, 2019
85eb8a0
Kepp @hidden tags in one line if no other JSDoc is present
merlinnot Jul 10, 2019
1c42e0e
Fix a typo - sentence ending with a comma
merlinnot Jul 10, 2019
8873af6
Merge branch 'master' into fix-issue-425
merlinnot Jul 11, 2019
6809ae5
Merge branch 'master' into fix-issue-425
merlinnot Jul 11, 2019
540fb95
Merge branch 'master' into fix-issue-425
merlinnot Jul 12, 2019
dbed779
Merge branch 'master' into fix-issue-425
merlinnot Jul 12, 2019
d741c04
Merge branch 'master' into fix-issue-425
merlinnot Jul 16, 2019
4cb2f28
Wrap JSDoc as specified in Google JavaScript Style Guide
merlinnot Jul 16, 2019
cd6b147
Move memory lookup table to functions-configuration and stricten type…
merlinnot Jul 17, 2019
06002e1
Move default failure policy to functions-configuration
merlinnot Jul 17, 2019
7b56f21
Separate standarization of options from construction of the options o…
merlinnot Jul 17, 2019
3a7c851
Rephrase failure policy description
merlinnot Jul 17, 2019
2e35c26
Rephrase description of memory and timeoutSeconds options
merlinnot Jul 17, 2019
4059b00
Simplify tests for invalid failure policies
merlinnot Jul 17, 2019
86b08cf
Merge branch 'master' into fix-issue-425
merlinnot Jul 17, 2019
2b95df9
Align public description of failure policies with a documentation of …
merlinnot Jul 17, 2019
d0e1a13
Merge branch 'fix-issue-425' of github.com:merlinnot/firebase-functio…
merlinnot Jul 17, 2019
006e11c
Merge branch 'master' into fix-issue-425
merlinnot Jul 17, 2019
31952e2
Add a missing dot in the Changelog
merlinnot Jul 18, 2019
668c02f
Minor stylistic changes to the documentation
merlinnot Jul 18, 2019
a89656c
Merge branch 'master' into fix-issue-425
merlinnot Jul 18, 2019
ac09c18
Make a test case more understandable
merlinnot Jul 19, 2019
7d3b4de
Merge branch 'master' into fix-issue-425
merlinnot Jul 19, 2019
f352933
Merge branch 'master' into fix-issue-425
samtstern Nov 25, 2019
1b6281f
Reformat
merlinnot Nov 25, 2019
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.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Allows specifying retry policies for event triggered functions.
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 1 addition & 3 deletions integration_test/functions/src/database-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ export const databaseTests: any = functions.database
.it('should have refs resources', (change, context) =>
expectEq(
context.resource.name,
`projects/_/instances/${process.env.GCLOUD_PROJECT}/refs/dbTests/${
context.params.testId
}/start`
`projects/_/instances/${process.env.GCLOUD_PROJECT}/refs/dbTests/${context.params.testId}/start`
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
)
)

Expand Down
4 changes: 1 addition & 3 deletions integration_test/functions/src/firestore-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export const firestoreTests: any = functions
.it('should have well-formatted resource', (snap, context) =>
expectEq(
context.resource.name,
`projects/${
process.env.GCLOUD_PROJECT
}/databases/(default)/documents/tests/${context.params.documentId}`
`projects/${process.env.GCLOUD_PROJECT}/databases/(default)/documents/tests/${context.params.documentId}`
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
)
)

Expand Down
11 changes: 2 additions & 9 deletions integration_test/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import * as admin from 'firebase-admin';
import { Request, Response } from 'express';
import * as fs from 'fs';

import * as PubSub from '@google-cloud/pubsub';
const pubsub = PubSub();

export * from './pubsub-tests';
export * from './database-tests';
export * from './auth-tests';
Expand Down Expand Up @@ -52,9 +49,7 @@ function callScheduleTrigger(functionName: string, region: string) {
{
method: 'POST',
host: 'cloudscheduler.googleapis.com',
path: `projects/${
firebaseConfig.projectId
}/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`,
path: `projects/${firebaseConfig.projectId}/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`,
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
headers: {
'Content-Type': 'application/json',
},
Expand Down Expand Up @@ -199,9 +194,7 @@ export const integrationTests: any = functions
resp
.status(500)
.send(
`FAIL - details at https://${
process.env.GCLOUD_PROJECT
}.firebaseio.com/testRuns/${testId}`
`FAIL - details at https://${process.env.GCLOUD_PROJECT}.firebaseio.com/testRuns/${testId}`
);
});
});
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-functions",
"version": "3.0.2",
"version": "3.1.0",
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
"description": "Firebase SDK for Cloud Functions",
"keywords": [
"firebase",
Expand Down Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"@types/cors": "^2.8.5",
"@types/express": "^4.11.1",
"@types/express": "^4.17.0",
merlinnot marked this conversation as resolved.
Show resolved Hide resolved
"@types/jsonwebtoken": "^8.3.2",
"@types/lodash": "^4.14.133",
"cors": "^2.8.4",
Expand All @@ -46,21 +46,21 @@
"@types/mock-require": "^2.0.0",
"@types/nock": "^10.0.2",
"@types/node": "^8.10.49",
"@types/sinon": "^7.0.12",
"@types/sinon": "^7.0.13",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"firebase-admin": "^8.0.0",
"firebase-admin": "^8.2.0",
"istanbul": "^0.4.2",
"mocha": "^6.1.4",
"mock-require": "^3.0.3",
"nock": "^10.0.6",
"prettier": "^1.17.1",
"prettier": "^1.18.2",
"sinon": "^7.3.2",
"ts-node": "^8.2.0",
"ts-node": "^8.3.0",
"tslint": "^5.17.0",
"tslint-no-unused-expression-chai": "^0.1.4",
"tslint-plugin-prettier": "^2.0.0",
"typescript": "^3.5.1"
"typescript": "^3.5.2"
},
"peerDependencies": {
"firebase-admin": "^8.0.0"
Expand Down
55 changes: 51 additions & 4 deletions spec/function-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,29 @@ describe('FunctionBuilder', () => {
it('should allow valid runtime options to be set', () => {
const fn = functions
.runWith({
timeoutSeconds: 90,
failurePolicy: { retry: {} },
memory: '256MB',
timeoutSeconds: 90,
})
.auth.user()
.onCreate((user) => user);

expect(fn.__trigger.availableMemoryMb).to.deep.equal(256);
expect(fn.__trigger.timeout).to.deep.equal('90s');
expect(fn.__trigger.failurePolicy).to.deep.equal({ retry: {} });
});

it("should apply a default failure policy if it's aliased with `true`", () => {
const fn = functions
.runWith({
failurePolicy: true,
memory: '256MB',
timeoutSeconds: 90,
})
.auth.user()
.onCreate((user) => user);

expect(fn.__trigger.failurePolicy).to.deep.equal({ retry: {} });
});

it('should allow both supported region and valid runtime options to be set', () => {
Expand Down Expand Up @@ -130,7 +145,39 @@ describe('FunctionBuilder', () => {
functions
.region('asia-northeast1')
.runWith({ timeoutSeconds: 600, memory: '256MB' });
}).to.throw(Error, 'TimeoutSeconds');
}).to.throw(Error, 'RuntimeOptions.timeoutSeconds');
});

it('should throw an error if user chooses a failurePolicy of type number', () => {
thechenky marked this conversation as resolved.
Show resolved Hide resolved
expect(() =>
functions.runWith({
failurePolicy: (1234 as unknown) as boolean,
})
).to.throw(Error, 'RuntimeOptions.failurePolicy');
});

it('should throw an error if user chooses a failurePolicy of type string', () => {
expect(() =>
functions.runWith({
failurePolicy: ('string-value' as unknown) as boolean,
})
).to.throw(Error, 'RuntimeOptions.failurePolicy');
});

it('should throw an error if user chooses a failurePolicy.retry of type number', () => {
thechenky marked this conversation as resolved.
Show resolved Hide resolved
expect(() =>
functions.runWith({
failurePolicy: { retry: (1234 as unknown) as object },
})
).to.throw(Error, 'RuntimeOptions.failurePolicy.retry');
});

it('should throw an error if user chooses a failurePolicy.retry of type string', () => {
expect(() =>
functions.runWith({
failurePolicy: { retry: ('string-value' as unknown) as object },
})
).to.throw(Error, 'RuntimeOptions.failurePolicy.retry');
});

it('should throw an error if user chooses an invalid memory allocation', () => {
Expand All @@ -152,13 +199,13 @@ describe('FunctionBuilder', () => {
return functions.runWith({
timeoutSeconds: 1000000,
} as any);
}).to.throw(Error, 'TimeoutSeconds');
}).to.throw(Error, 'RuntimeOptions.timeoutSeconds');

expect(() => {
return functions.region('asia-east2').runWith({
timeoutSeconds: 1000000,
} as any);
}).to.throw(Error, 'TimeoutSeconds');
}).to.throw(Error, 'RuntimeOptions.timeoutSeconds');
});

it('should throw an error if user chooses an invalid region', () => {
Expand Down
Loading