簡體   English   中英

使用 pubsub 重試 Firebase 函數

[英]Retry on Firebase functions with pubsub

我正在使用帶有 pubsub 的 firebase 函數。 每次有傳入消息(推送)時都會調用這些函數,我正在考慮為這些函數合並重試機制。 重試不起作用。 示例函數如下所示。

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")
        
    });

在這些情況下是否有可能使用重試? 文檔說該消息在函數調用時立即ack

將消息放回隊列或拉方法是實現重試的唯一合乎邏輯的方法嗎?

可以將這些功能配置為重試失敗 -請參閱文檔

並在代碼中執行此操作 -

functions.runWith({failurePolicy: true}).foo.onBar(myHandler);

因此,您需要做的就是確定哪些類型的異常是可重試的,並將它們從您的函數中拋出。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM