mlasevich / PyRSMQ

Python Implementation of Redis Simple Message Queue Algorithm
Apache License 2.0
44 stars 10 forks source link

Allow more commands to happen in the same transaction as deleteMessage #9

Closed yehonatanz closed 4 years ago

yehonatanz commented 4 years ago

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__

mlasevich commented 4 years ago

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...

yehonatanz commented 4 years ago

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.

mlasevich commented 4 years ago

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