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

Support for functions failure policies #1858

Merged
merged 8 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
- Fixes issue where all database functions triggered on the default namespace (#2501)
- Fixes issue where rules paths were not normalized before reading (#2544)
- Functions emulator waits for all functions to finish before exiting (#1813)
- Adds support for deploying functions with a failure policy.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"eslint-plugin-prettier": "^3.1.0",
"firebase": "^7.14.0",
"firebase-admin": "^8.9.0",
"firebase-functions": "^3.8.0",
"firebase-functions": "^3.10.0",
"mocha": "^7.1.1",
"nock": "^9.3.3",
"nyc": "^15.0.1",
Expand Down
41 changes: 40 additions & 1 deletion src/deploy/functions/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,47 @@ module.exports = function(context, options, payload) {
var deleteReleaseNames;
var existingScheduledFunctions;

// Collect all the functions that have a retry policy
var failurePolicyFunctions = functionsInfo.filter((fn) => {
return !!fn.failurePolicy;
});

var failurePolicyFunctionLabels = failurePolicyFunctions.map((fn) => {
return helper.getFunctionLabel(_.get(fn, "name"));
});
var retryMessage =
"The following functions will be retried in case of failure: " +
clc.bold(failurePolicyFunctionLabels.join(", ")) +
". " +
"Retried executions are billed as any other execution, and functions are retried repeatedly until they either successfully execute or the maximum retry period has elapsed, which can be up to 7 days. " +
"For safety, you might want to ensure that your functions are idempotent; see https://firebase.google.com/docs/functions/retries to learn more.";

utils.logLabeledWarning("functions", retryMessage);

let proceedPrompt = Promise.resolve(true);
if (options.nonInteractive && !options.force) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check if there are any functions with a retry policy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooooh ... I think so! Want to send a PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or I can do it, but you deserve the glory)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the opportunity but I have a lot to do right now. =]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@armordog done and released!
https://github.com/firebase/firebase-tools/releases/tag/v8.8.1

Thank you for catching that! Saved me a lot of angry emails in the morning :-)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was fast!
Thanks so much. =]

throw new FirebaseError("Pass the --force option to deploy functions with a failure policy", {
exit: 1,
});
} else if (!options.nonInteractive) {
proceedPrompt = promptOnce({
type: "confirm",
name: "confirm",
default: false,
message: "Would you like to proceed with deployment?",
});
}

delete payload.functions;
return Promise.resolve(context.existingFunctions)

return proceedPrompt
.then((proceed) => {
if (!proceed) {
throw new FirebaseError("Deployment canceled.", { exit: 1 });
}

return Promise.resolve(context.existingFunctions);
})
.then(function(existingFunctions) {
var pluckName = function(functionObject) {
return _.get(functionObject, "name"); // e.g.'projects/proj1/locations/us-central1/functions/func'
Expand Down
2 changes: 2 additions & 0 deletions src/functionsDeployHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ function getFunctionTrigger(functionInfo) {
return _.pick(functionInfo, "httpsTrigger");
} else if (functionInfo.eventTrigger) {
var trigger = functionInfo.eventTrigger;
trigger.failurePolicy = functionInfo.failurePolicy;
return { eventTrigger: trigger };
}

logger.debug("Unknown trigger type found in:", functionInfo);
return new FirebaseError("Could not parse function trigger, unknown trigger type.");
}
Expand Down