Comments (3)
The test basically just sets a key to 0, then attempts to run the job 100 times (in ten separate threads to simulate multiple processes/servers), then it sleeps for a second to allow the background job(s) to run and checks the value in the counter.
As you can see multiple jobs end up getting run (9 in the case above) and the counter gets incremented more than once.
I think this is caused by the fact that the uniqueness key is being cleared when the job is completed, but this means that the uniqueness window is closed immediately rather than letting it expire after the desired amount of time.
Am I misunderstanding how this gem is supposed to work or is this a bug?
from sidekiq-unique-jobs.
I just updated my test to be a bit more thorough. I gave the worker a :unique_job_expiration => 10
and changed my test to try to queue up 100 workers, wait 3 seconds try to queue another 100 and finally wait 10 seconds and try to queue another 100 workers. So the final expected counter value would be 2, but I get this:
$ ruby test_uniqueness.rb
2014-02-26T22:35:07Z 70948 TID-znnu9k INFO: Sidekiq client with redis options {:url=>"redis://localhost:6379", :namespace=>"sk"}
Expecting counter = 1
counter = 7
Expecting counter = 1
counter = 16
Expecting counter = 2
counter = 25
I also confirmed that removing the unlock from lib/sidekiq-unique-jobs/middleware/server/unique_jobs.rb
fixes this and makes the test run correctly.
from sidekiq-unique-jobs.
Perhaps this could be improved since people do seem to have some trouble with figuring it out. First of all you need to add the sidekiq-unique-jobs
gem. Secondly
If you change your worker to
class Incrementer
include Sidekiq::Worker
sidekiq_options :unique => true, :unique_job_expiration => 10, :unique_unlock_order => :never
def perform
Sidekiq.redis do |conn|
conn.incr :counter
end
end
end
it should work like you expected where the uniqueness window is kept even though the job has been successfully processed. I created a pull request for you mmmries/sidekiq-not-unique-jobs#1
from sidekiq-unique-jobs.
Related Issues (20)
- Large retry queue causes reaper to run too slow HOT 3
- 8.0.1 Time on locks & changelog UI is incorrect/wrong HOT 5
- Jobs queued during existing job inherit lock digest HOT 1
- My configuration is correct or not. Because uniq job not remove all job process in sidekiq ?
- Redis server v6.0 compatibility HOT 4
- `while_executing` with `on_conflict: :reschedule` reschedules job when unlock fails HOT 7
- Problems with reaper and long running jobs HOT 11
- Migrate away from deprecated Redis commands HOT 2
- `unlocked` reflection is never called
- Logging::Middleware.context can include empty string as key when lock is not set in job hash HOT 1
- PRIMED key grows indefinitely when job re-queues itself in `after_unlock` callback HOT 1
- until_and_while_executing and lock_ttl: jobs silently dropped HOT 3
- incompatibility with sidekiq-failures HOT 4
- Deprecation Warning: Use of rpoplpush command in Redis HOT 1
- Redis has deprecated the `rpoplpush`command
- Release new gem version with "fix replace deprecated rpoplpush w/lmove" HOT 3
- `while_executing` with `on_conflict: :reschedule` Reschedule job after job execution HOT 7
- Reaper manager registration is subject to race conditions HOT 1
- Should client middleware also be added to the Sidekiq server config? HOT 2
- After sidekiq shutdown (with running job) lock digest is not pushned back HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sidekiq-unique-jobs.