Update takes long time
sashokbg opened this issue · 2 comments
I am updating my runtime variable with following command:
gcloud beta runtime-config configs variables set var "value" --is-text --config-name global
When I check the provided direct URL I can see that the variable is well updated in google cloud.
Unfortunately when I call my function the variable keeps its old value and takes as long as 15 minutes to get updated.
const runtimeConfig = require('cloud-functions-runtime-config');
const environment = runtimeConfig.getVariable('global', 'var');
exports.helloWorld = (req, res) => {
environment
.then((val) => res.status(200).send(`Var is ${val}`))
.catch((err) => res.status(500).send(`Problem resolving var: ${err}`));
};
Try this:
const runtimeConfig = require('cloud-functions-runtime-config');
exports.helloWorld = (req, res) => {
return runtimeConfig.getVariable('global', 'var')
.then((val) => res.status(200).send(`Var is ${val}`))
.catch((err) => res.status(500).send(`Problem resolving var: ${err}`));
};
The difference is that this example does a lookup at the time of invocation instead of during the creation of a new function instance. GCP may reuse function instances, that's why we might see the same value for a while when we do the lookup in global scope.
@DazWilkin has written a great article that explains the different scopes here.
It was precisely that ! Sorry for the false alert :)