Closed bolshakov closed 10 years ago
Can you give me a use case?
I'm verifying iTunes receipt with Sidekiq worker:
class ItunesVerifier
include Sidekiq::Worker
include Redis::Mutex::Macro
auto_mutex :perform, block: 0
def perform(transaction_id)
...
end
end
It's ok if different receipts would be verified in the same time. But I don't want same receipts to be verified twice.
I can see the value, but the implementation lacks the flexibility of what should be included / excluded as a key, which seems too limiting to me.
For instance, it can go wrong like this:
def perform(transaction_id, options = {})
...
end
perform(100, {a:1,b:2})
=> "ItunesVerifier#perform:100:{:a=>1, :b=>2}" # key
I prefer a clearer API like so:
auto_mutex :perform, on: [:transaction_id]
Sounds reasonable. Please, check out my latest commit.
Awesome, thanks!
Just released as 3.0.0
Now you can optionally pass
with_args: true
option toauto_mutex
method to include method's arguments to mutex redis key.