我正在努力改進使用Firestore. 我想確保Firestore在事務完成后清理事務的一些位。而不是這樣做,我可能會選擇在一個事務中運行事務和清理。但是,我相信如果不進行其他架構更改,這也可能會引入競爭條件。
無論如何,在解決這個問題時,我意識到我不知道一種方法(除了制作任務佇列)在Firestore.
我認為下面的玩具示例將有助于解釋我想要做什么。
// push cleanup task to Firestore to execute in 3000ms
await dispatchTransactionCleanup({id : "xxx", inMs : 3000}); // !important
// run the actual transaction, which should not take more than 1000 ms
await runMyTransaction({id : "xxx"});
// also dispatch a cleanup here, to reduce latency over the other cleanup.
// but, importantly this cleanup isn't guaranteed to run, e.g.,
// the server crashes between request to run transaction
// and this part of the program.
await runManualCleanup({id : "xxx"});
那么,我將如何dispatchTransactionCleanup在未來的某個時候運行一次性任務?如果沒有我自己的任務佇列,這可能嗎?或者,我需要引入額外的結構嗎?
uj5u.com熱心網友回復:
Firestore 沒有任何“任務”或“佇列”的含義。它只是在您進行 API 呼叫時回應您進行的呼叫。
如果您想要一個排隊機制,您將不得不構建它,也許使用其他一些軟體產品。您已經鏈接到一個在后端使用 Cloud Functions 的解決方案。
您可能想重新考慮在單個事務中簡單地完成所有作業。目前尚不清楚您為什么認為這會有問題。也許您可以發布第二個問題,以更詳細地解釋您嘗試過的事情不會按您期望的方式作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/484889.html
