diff --git a/Rakefile b/Rakefile index 080b87f..e3d7aa8 100644 --- a/Rakefile +++ b/Rakefile @@ -22,13 +22,17 @@ task :web do } end - # throw a fake job in + # throw some fake jobs in Sidecloq.configure do |config| sched = Sidecloq::Schedule.from_hash({ my_scheduled_job: { class: 'DoWork', cron: '* * * * *', queue: 'default' + }, + my_scheduled_job2: { + class: 'DoWorkWithQueue', + cron: '* * * * *' } }) sched.save_redis @@ -39,6 +43,11 @@ task :web do include Sidekiq::Worker end + class DoWorkWithQueue + include Sidekiq::Worker + sidekiq_options queue: "not_default" + end + require 'sidekiq/web' require 'sidecloq/web' require 'securerandom' diff --git a/lib/sidecloq/web.rb b/lib/sidecloq/web.rb index 7481751..db75211 100644 --- a/lib/sidecloq/web.rb +++ b/lib/sidecloq/web.rb @@ -5,7 +5,15 @@ module Web def self.registered(app) app.get '/recurring' do - @schedule = Schedule.from_redis + @job_specs = Schedule.from_redis.job_specs + @job_specs.each_value do |job_spec| + job_spec['cron'] ||= job_spec['every'] + + job_spec['queue'] ||= begin + klass = Object.const_get(job_spec['class']) + (klass.sidekiq_options_hash && klass.sidekiq_options_hash.fetch('queue', 'default')) || 'default' + end + end erb File.read(File.join(VIEW_PATH, 'recurring.erb')) end diff --git a/test/helper.rb b/test/helper.rb index a95b814..fc2cca8 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -52,6 +52,11 @@ class DummyJob include Sidekiq::Worker end +class DummyJobWithQueue + include Sidekiq::Worker + sidekiq_options :queue => "dummy" +end + require 'active_job' ActiveJob::Base.queue_adapter = :sidekiq diff --git a/web/views/recurring.erb b/web/views/recurring.erb index c34ca8a..c6f3a3a 100644 --- a/web/views/recurring.erb +++ b/web/views/recurring.erb @@ -14,13 +14,13 @@ - <% @schedule.job_specs.each do |name, job_spec| %> + <% @job_specs.each do |name, job_spec| %> <%= name %> - <%= job_spec.fetch 'cron', job_spec['every'] %> + <%= job_spec['cron'] %> <%= job_spec['class'] %> - <%= job_spec.fetch('queue', 'default') %> + <%= job_spec['queue'] %> <%= job_spec['args'] %>