mlasevich/PyRSMQ

Allow more commands to happen in the same transaction as deleteMessage

yehonatanz opened this issue · 3 comments

The deleteMessage command serves as an ACK that signals a job is done.
In some cases (mine included), the worker ACKing the job also writes its output to the same redis instance holding the queue.
In such cases, it would be great if writing a job's output and ACKing it will happen within the same transaction, to provide the ultimate atomicity guarantee.
I propose the following syntax:

with rsmq_instance.deleteMessage(id=message_id).transaction() as tx:
    tx.set("output", output)

Where tx is a Pipeline instace pre-populated with the deleteMessage commands and is executed upon __exit__

Interesting. I would need to look to see if the transaction is handled in code or in the Lua script - if in code, this should be doable I would think...

Good news! I just checked, deleteMessage uses only a simple transaction with two commands (zrem and hdel).
Exposing this transaction should be pretty simple.
I will submit a POC PR.

This should be released with 0.4.4+ (somehow Travis/Pypi refused to release it, checking on it now)