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

Added method in testing for running only due jobs #334

Closed
wants to merge 1 commit into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+41 −0
Diff settings

Always

Just for now

Copy path View file
@@ -39,6 +39,18 @@ def drain
new.perform(*job['args'])
end
end
def drain_due_jobs
scheduled = []
while job = jobs.shift do
if (at = job['at']) && at > Time.now.to_f
scheduled << job
else
new.perform(*job['args'])
end
end
jobs.concat(scheduled)
end
end
end
end
Copy path View file
@@ -25,4 +25,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rake'
gem.add_development_dependency 'actionmailer', '~> 3'
gem.add_development_dependency 'activerecord', '~> 3'
gem.add_development_dependency 'timecop'
end
Copy path View file
@@ -3,6 +3,7 @@
require 'sidekiq/worker'
require 'active_record'
require 'action_mailer'
require 'timecop'
require 'sidekiq/rails'
require 'sidekiq/extensions/action_mailer'
require 'sidekiq/extensions/active_record'
@@ -34,6 +35,13 @@ def perform(error)
end
end
class ScheduledWorker
include Sidekiq::Worker
def perform(error)
raise PerformError if error
end
end
class FooMailer < ActionMailer::Base
def bar(str)
str
@@ -98,5 +106,25 @@ def bar(str)
end
assert_equal 0, StoredWorker.jobs.size
end
it 'executes all scheduled jobs' do
assert ScheduledWorker.perform_in(10, true)
assert ScheduledWorker.perform_async(false)
assert_equal 2, ScheduledWorker.jobs.size
ScheduledWorker.drain_due_jobs
assert_equal 1, ScheduledWorker.jobs.size
Timecop.travel(Time.now + 5) do
ScheduledWorker.drain_due_jobs
assert_equal 1, ScheduledWorker.jobs.size
Timecop.travel(Time.now + 5) do
assert_raises PerformError do
ScheduledWorker.drain_due_jobs
end
assert_equal 0, ScheduledWorker.jobs.size
end
end
end
end
end
ProTip! Use n and p to navigate between commits in a pull request.