[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

Support for functions failure policies #1858

Merged
merged 8 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
- Includes latest features and improvements from production in the Firestore Emulator.
- Fixes issue where all database functions triggered on the default namespace (#2501)
- Fixes issue where rules paths were not normalized before reading (#2544)
- Adds support for deploying functions with a failure policy.

5 changes: 2 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": "file:firebase-functions-3.9.1.tgz",
samtstern marked this conversation as resolved.
Show resolved Hide resolved
"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 multiple days. " +
samtstern marked this conversation as resolved.
Show resolved Hide resolved
"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