1
votes

I have multiple cloud functions that use a single value, basically something like this:

index.js

function emailFooter() {
    return `<div>email footer</div>`;
}

exports.sendEmailSuccess = functions.https.onCall(() => {
    const emailContent = 'success content' + emailFooter();
    sendEmail(emailContent) // fake email sender
});

exports.sendEmailFailure = functions.https.onCall(() => {
    const emailContent = 'failure content' + emailFooter();
    sendEmail(emailContent) // fake email sender
});

The problem is that I want to change the footer content (returned by emailFooter), but in order to do so (as far as I've researched) I first have to change it in the code and then deploy every single cloud function that uses emailFooter (sendEmailSuccess and sendEmailFailure), so the footer will look the same on each type of email.

Of course, I could just deploy all the functions at the same time with firebase deploy --only functions, but we used to be multiple developers and some of us updated functions to the point we don't know which ones are the same in index.js as in GCP (about 20 functions) and I'd have to check each one so I wouldn't deploy an old version.

Is there a way to update this single value or at least know which functions are up to date?

Thanks.

1

1 Answers

4
votes

If the single value can only be provided by code, then there is no way to update that value without also redeploying each function. Code is not shared between function instances - each one has its own copy.

If you want to share a value between functions, and it can change over time, you will need to put that value somewhere else, for example, a database. Each function can then query that other source for the value, even after it changes.