Lindauson
Lindauson

Reputation: 3441

How should I replicate Firebase Queue data properties in Cloud Functions for Firebase?

Firebase Queue uses the following properties to track processing:

_state _state_changed _owner _progress _error_details _id

I am migrating some of my Firebase Queue code to Cloud Functions for firebase. How would I obtain an equivalent data property for the _owner property?

Alternatively, considering this property is primarily to alleviate issues with concurrency, does Cloud Functions already resolve this issue in another way making my implementation unnecessary?

Upvotes: 1

Views: 164

Answers (2)

Lindauson
Lindauson

Reputation: 3441

The _state and _state_changed properties should be more than adequate to resolve concurrency issues (specifically, race-conditions) within Google Cloud Functions for Firebase (I'm still investigating how Google resolves this internally).

However, having an _owner property would be additionally helpful in instances where there was multi-platform task workers.

Upvotes: 0

Chris Raynor
Chris Raynor

Reputation: 1695

The semantics are a little different between the two systems. The primary reason for the _owner property in Firebase Queue is that it can't kill user code once the lease for an operation expires, and so we have to guard any side-effects of the processing function with a check. Cloud Functions controls the execution environment and can kill user code if needed, so we can assume if it's writing, then it still has the lease.

In order to emulate the behavior, it would be possible to generate a v4 UUID at the start of every Cloud Function execution, write that back to the database somewhere with a timestamp so you can timeout leases (guarded by a transaction so you don't clobber other owners), then compare those with the current UUID and time in a transaction every time you write back to the database in your function.

Upvotes: 2

Related Questions