WithTimestampResolution option for RedisQueue#69
WithTimestampResolution option for RedisQueue#69josephbuchma wants to merge 1 commit intotaylorchu:masterfrom
Conversation
|
do you have thousands of jobs that are enqueued within 1 second? |
Yes, but that's not the reason. Although I agree that use case I have is rather uncommon (more on that below), having this option (or just using milliseconds by default) does not cost much. I don't want to take too much of your time, but if you are interested in my use case, here are details.
|
|
For your use case, you can use uuid as job id, and put both record id and version number in the payload. On job execution, compare version number, and decide whether to proceed. It sounds like you should only enqueue without delay "after" the row is committed. Because if any error happens during commit, the version number won't be updated, and this job does not need to run. Also if your database does not commit within 100ms, then it will cause race condition. |
That is how it's currently done. I'll do a bit more investigation regarding your concerns about expensiveness of deduplication logic.
We do that on updates. On inserts we enqueue first, because it's basically a no-op if we fail to insert the record right after. After few job retries we consider insert failed and give up. Similarly with 100ms delay. In most cases insert will happen much faster. In rare cases when it doesn't, job will pick it up on retry. |
Currently timestamps are truncated to second resolution. This change allows to override that, so it's possible to enqueue 200ms into the future, for example.