From 69de50afea45c665564f3e4e9a534fb50aeec563 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Fri, 5 Aug 2022 17:33:18 -0400 Subject: [PATCH] Fix presentation of the Queue in the Recurring Jobs page Fixes #38 --- Rakefile | 11 ++++++++++- lib/sidecloq/web.rb | 10 +++++++++- web/views/recurring.erb | 6 +++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index 43632f3..503ffa9 100644 --- a/Rakefile +++ b/Rakefile @@ -21,13 +21,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 @@ -38,6 +42,11 @@ task :web do include Sidekiq::Worker end + class DoWorkWithQueue + include Sidekiq::Worker + sidekiq_options queue: "not_default" + end + require 'rack/server' require 'rack/session/cookie' require 'sidekiq/web' diff --git a/lib/sidecloq/web.rb b/lib/sidecloq/web.rb index 7d6acdb..7cfab32 100644 --- a/lib/sidecloq/web.rb +++ b/lib/sidecloq/web.rb @@ -6,7 +6,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/web/views/recurring.erb b/web/views/recurring.erb index f61c46f..b854eb5 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'] %>