-
-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jobs scheduled in the future are never run #93
Comments
BTW, I'm happy to work on a pull-request for this, but wanted to start a discussion first to make sure I understand the context. |
@mhenrixon thanks for the update. |
Could you post a failing test for this @amiel ? |
@mhenrixon I'll give it a shot. Do you have a suggestion as to where this test should live? |
Just add it to the issue description and tell me when its done. Oh and please base it on current master! |
@mhenrixon ok, will do. |
@mhenrixon I'm having a hard time replicating this issue in tests. However, I can replicate it with the current master. Here's what I've done to troubleshoot:
Here is the test I wrote, but I could not get it to fail: require 'spec_helper'
require 'sidekiq/api'
require 'sidekiq/worker'
require 'sidekiq-unique-jobs'
require 'sidekiq/scheduled'
describe 'Unique scheduled jobs' do
class TestWorker
include Sidekiq::Worker
sidekiq_options unique: true, queue: 'default',
unique_unlock_order: :never, unique_unlock_expiration: 10
def perform
end
end
describe 'with real redis' do
let(:scheduled) { Sidekiq::ScheduledSet.new }
let(:enqueuer) { Sidekiq::Scheduled::Enq.new }
let(:past) { (Time.now - 60).to_f }
before do
Sidekiq.redis = REDIS
Sidekiq.redis(&:flushdb)
end
it 'enqueues a scheduled job' do
scheduled.schedule past, 'class' => TestWorker.name, 'args' => []
enqueuer.enqueue_jobs
default_queue = Sidekiq::Queue.new('default')
expect(default_queue.size).to eq 1
end
end
end I did notice this spec. My assumption is that the tests aren't able to replicate the issue as they only use the client middleware stack and not the server middleware stack, but I don't understand what else could be contributing to this issue. @mhenrixon Would it help if I could create an example application? Thanks for taking the time to look in to this :) |
I can confirm that I observe this same behavior in our own application. Any workers that use |
Example app works as good as a failing test @amiel |
@mhenrixon Try this out: https://github.com/amiel/sidekiq-unique-scheduled-job-example Let me know if you need any more details. Thanks again for looking in to it 😀 |
This is related to #97. The problem is that in |
@mhenrixon This is because middleware is invoked twice for a scheduled job right? Once to schedule and once to push it into it's queue once the If the intent is to actually have one mutex for scheduled and queued it would be simple to check if the current_job is the owner of the mutex (compare JID) and let it run if it is (instead of using setnx). Although it may be quite sub-optimal to use the same mutex for scheduled and queued jobs to begin with. Thoughts? |
Check against master and report back if this is still an issue. The recent commits should have fixed this issue. |
@mhenrixon Yay! I'm not currently developing any projects that use sidekiq-unique-jobs right now, but I'll report back when I do :) |
Here's what I think is happening:
Worker.perform_in 1.minute, args
), it runs through the clients client middleware, setting the unique lock.The servers client middleware was introduced in ea06539. Could it be safely removed? Or am I misunderstanding the issue?
The text was updated successfully, but these errors were encountered: