-
Notifications
You must be signed in to change notification settings - Fork 204
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
Conversation
Travis fails on Node.js 10, because it can't install it. CI passes on Node.js 8. |
Hey @merlinnot just rerun the job if it fails on stuff like installing Node 10, it usually is a transient error. I just reran your last one and it passed. |
Great, thanks! The PR is ready for a first pass, please not the question in the description of the PR. |
@thechenky Hey, just a friendly ping for a review :) |
Ah, will get to this in a bit - for future reference, please add me as reviewer at the top so that I understand it's ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a loooooooooot of code changes here that are unrelated to the actual feature which makes it very hard to review. I've made a lot of comments here, mostly around pulling these changes out into separate PRs. I'm thinking you need two extra PRs - one for formatting/comment changes, and one for refactors you made around pulling out configuration and changing opts => options.
Please do this, add me as reviewer on all the other PRs so that I can review them separately. Then I will review the code that's left in this PR, which should just be the feature. Also btw, we will be needing CLI changes to parse __trigger to pluck out the extra retry options and supply them in the API to GCF.
I'll extract opts -> options rename and comments fixes to separate PRs once the three new ones I created are merged, it will be easier for me to extract these changes. |
Sounds good. Reviewing the others now. |
@merlinnot looks like you might need to run prettier on this one more time before we can merge? I merged |
@samtstern Done! |
Thanks @merlinnot ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Revert "Allow specifying failure policies (#482)
Any ideas when this is going to be re-merged back in / released? |
Good call! @samtstern Is the work in the CLI complete? |
I know this sounds pathetic but no matter what I tried I could not get this to work, the GCF API did not seem to be taking my PATCH requests. @tinaliang I'll bring you into the internal thread. |
Hi I find workaround, you can define your functions like this: const functions = require('firebase-functions')
const fn = functions.firestore
.document('/collection/{item_id}')
.onWrite(async (change, context) => {
// duno
return 0
})
module.exports = new Proxy(fn, {
get(target, phrase) {
const obj = target[phrase]
if (phrase === '__trigger') obj.eventTrigger.failurePolicy = { retry: {} }
return obj
}
}) |
@merlinnot I may be mistaken here, but the current firebase docs do not reflect this change, correct? https://firebase.google.com/docs/reference/functions/function_builder_.functionbuilder#runwith |
@cjimmy you're right looks like we need to regenerate the reference docs, thanks for the reminder! |
Here are some notes, for my future self and others. For anyone looking add retries to firebase functions, without having to use GCP console, this PR is it and enabled in export const myFirebaseFunc = functions
.runWith({
failurePolicy: {
retry: {},
},
memory: '512MB',
timeoutSeconds: 60,
})
.firestore.document('/path/to/some/doc')
.onCreate(async (snap, context) => {
/* do stuff */
}) Right now, it looks like the failure policy is simply on or off. Thus, this is equivalent export const myFirebaseFunc = functions
.runWith({
failurePolicy: true,
memory: '512MB',
timeoutSeconds: 60,
})
.firestore.document('/path/to/some/doc')
.onCreate(async (snap, context) => {
/* do stuff */
}) Some caveats:
Read this: https://firebase.google.com/docs/functions/retries and make sure your function in idempotent. It was also difficult to discover what to return to force a retry or avoid a retry. A Firebase function will retry if:
That means that if you run into an error that you know won't eventually resolve itself with a retry (i.e. you want to stop the function execution and not retry), you can |
This PR:
FailurePolicy
, which can be specified for all functions.FailurePolicy
is used forhttps
functions. Originally I planned to express it using more correct typings, it's doable, but not very clean. It's tricky because the runtime options are specified before the function trigger is chosen, so specifying a retry policy would result in limiting the number of options for triggers (removinghttps
). We'd either need two classes returned conditionally based on the config (EventTriggeredFunctionBuilder
when retry policy is specified, currentFunctionBuilder
otherwise) or we can just have this warning and ignore this option forhttps
functions. Let me know which approach do you like better.FailurePolicy
in__trigger
, so it can be consumed byfirebase-tools
.failurePolicy
.I'm wondering how to approach releasing this functionality. Should we first implement support for it in
firebase-tools
, release a new version of it and start requiring it inpeerDependencies
? It would be weird if it's allowed to specify it here, but the setting is ignored by the CLI.Description
Resolves #425.
Code sample
The API change is described in the issue linked above.