The following scenario with the Pyramid web framework. Within a view handler a new db object is created and added to the view’s db transaction, i.e. the object will be persisted upon successful view execution. In that same view a Dramatiq actor is called, and that actor needs to access the created db object.
We have a race here between the db object being persisted before the actor reads from the db:
- The clean solution would be to send the message only when the view was successul (and after the view’s db transaction has committed).
- The hacky solution would be to use the
send_with_options(…, delay=n)function, but it seems that
delaycauses a short synchronous wait (i.e. it would stall the view handler) rather than an asynchronous message delivery?
- Poll on the actor side until the object appears in the actor’s db session (worse than 2. me thinks).
What other options do exist? Is there a “queue messages and send later” approach already available?