mirror of
https://github.com/hibiken/asynq.git
synced 2026-04-26 07:25:56 +03:00
[GH-ISSUE #119] [FEATURE REQUEST] Support unique jobs #1046
Labels
No labels
CLI
bug
designing
documentation
duplicate
enhancement
good first issue
good first issue
help wanted
idea
invalid
investigate
needs-more-info
performance
pr-welcome
pull-request
question
wontfix
work in progress
work in progress
work-around-available
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/asynq#1046
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cayter on GitHub (Mar 15, 2020).
Original GitHub issue: https://github.com/hibiken/asynq/issues/119
Originally assigned to: @hibiken on GitHub.
Is your feature request related to a problem? Please describe.
Any chance we would be supporting this? More details can be found here. Thanks.
@hibiken commented on GitHub (Mar 15, 2020):
Thanks for opening this issue!
I've seen Sidekiq and other libraries supporting uniqueness of tasks(jobs) in Redis. It sounds like a useful feature to include, and I'm onboard with adding this feature to this package.
I haven't personally used this feature in the past. Would you mind adding more context as to why/when you would need this feature?
I've taken a look at Sidekiq's uniqueness feature and it seems like they support uniqueness based on
(type, args, queue)of a task, which seems reasonable. The semantics around uniqueness TTL (unique_for: <duration>) is a bit confusing to me, especially when you consider task retries.For example, in Sidekiq, if you set
unique_for: 10.minutesinMyWorkerclass, a job of that class is guaranteed to be unique in the next 10 mins or until that first job is processed successfully. But the doc states thatI'm not quite sure if this is the behavior we want from the uniqueness feature.
I think I need to think this through and come up with something more intuitive and simpler to understand (better for both implementors & users of the package).
@cayter commented on GitHub (Mar 16, 2020):
Here's 1 use case example: https://blog.francium.tech/avoiding-duplicate-jobs-in-sidekiq-dcbb1aca1e20.
In general, when we have a set of servers running behind a load balancer, it's very likely our servers would enqueue multiple jobs that do the same thing. As such, having the unique job feature would ensure that we don't enqueue the same job multiple times and waste redundant computing resource(especially when it's writing into the SQL DB).
In my current job where payment gateways would sometimes hit our webhook endpoint with the exact same payload multiple times(can be within a short period of time), this leads to some issues on updating the same data in the SQL database which can be redundant/incorrect.
@hibiken commented on GitHub (Mar 16, 2020):
I see. Thank you for the link and the explanation!
After reading the use cases and Sidekiq's wiki, it sounds like it's reasonable to have best-effort uniqueness (i.e., If unique TTL expires then it's okay to enqueue a duplicate task) .
Here's my initial proposal for the API of the feature (Please provide feedback!).
Provide a function to create uniqueness option.
Example of enqueueing a task:
Example of scheduling a task (I have two proposals):
Option 1: Treat TTL the same as
Enqueue, so TTL behaves the same.Option 2: TTL behaves differently when using scheduling (TTL is set to
delay + duration_provided_by_unique)I'm not sure if we want to treat uniqueness TTL differently when scheduling like Sidekiq does. Let me know your thoughts.
Return
ErrDuplicateTaskwhen usingUniqueoption and duplicate exists.Retry should be treated the same as Sidekiq does:
I don't think we need this Unlock Policy. Let me know if you disagree!
For bypassing uniqueness, I suggest that we also provide an option to do so:
Example for ignoring uniqueness:
Let me know your thoughts and feedback!
@cayter commented on GitHub (Mar 17, 2020):
I am leaning towards option 2 as this library is gonna be made friendly to those who had used Sidekiq before.
The suggestion is good.
The suggestion is good.
I just roughly looked into the possible options here. I can imagine how much efforts we need to put into to support all of them. So, I wouldn't be pushing for it now as I think the default policy which is unlocking right after a job is successfully processed should be sufficient for most use cases.
Question
We're planning to support this uniqueness across multiple workers yeah? Thanks!
@hibiken commented on GitHub (Mar 17, 2020):
If your worker processes are connecting to the same Redis instance, then answer is yes. My thought is to create a lock key in Redis with the given TTL and check that before inserting the task into Redis.
I'm currently planning the feature right now. I should be able to get started on this feature in the next few days 👍
Additional Note: While I was planning this feature, I realized that we do not need
IgnoreUniqueoption since simply omitting theUniqueoption when enqueuing should give you the same effect.