'Retry on Firebase functions with pubsub
I am using firebase functions with pubsub. The functions are invoked every time there is an incoming message (push) I am looking at incorporating retry mechanism for the functions. The retry is not working. The sample function is shown below.
export const helloWorldWithRetry = functions
.runWith({
timeoutSeconds: 300,
memory: "512MB",
vpcConnector: cloudFunctionOptions.connectors["abcd_data_connector"],
vpcConnectorEgressSettings: "ALL_TRAFFIC",
maxInstances: 1,
failurePolicy: {
retry: {},
}
})
.region("asia-south1")
.pubsub.topic("helloWorldPubSubWithRetry")
.onPublish(async (message, context) => {
console.log("----------- ATTEMPTING -------------")
const eventAgeMs = Date.now() - Date.parse(context.timestamp);
console.log(`The event timestamp is ${Date.parse(context.timestamp)} and eventAge is ${eventAgeMs}`)
const eventMaxAgeMs = 60 * 1000;
if (eventAgeMs > eventMaxAgeMs) {
console.log(`Dropping event with age[ms]: ${eventAgeMs}`);
return;
}
throw new Error("Error, Retry")
});
Is there a possibility to use retry in these cases? The documentation says that the message is ack
immediately on function invocation
Is putting the message back on queue or pull method the only logical way to achieve retries ?
Solution 1:[1]
The functions can be configured to retry the failures - refer docs.
And do this in the code -
functions.runWith({failurePolicy: true}).foo.onBar(myHandler);
So all you need to do is identify what kind of exceptions are re-triable and throw them from your function.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rahul Nimbal |