Skip to content

Commit

Permalink
Support for functions failure policies (#1858)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern authored Aug 20, 2020
1 parent 2b6fa69 commit e92ba5a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
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) {
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

0 comments on commit e92ba5a

Please sign in to comment.