Skip to content

Commit

Permalink
Fix presentation of the Queue in the Recurring Jobs page
Browse files Browse the repository at this point in the history
Fixes mattyr#38
  • Loading branch information
Fryguy committed Aug 5, 2022
1 parent 4783b83 commit 937f0e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
11 changes: 10 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
10 changes: 9 additions & 1 deletion lib/sidecloq/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions web/views/recurring.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
</thead>

<tbody>
<% @schedule.job_specs.each do |name, job_spec| %>
<% @job_specs.each do |name, job_spec| %>
<tr>
<td><%= name %></td>
<td><%= job_spec.fetch 'cron', job_spec['every'] %></td>
<td><%= job_spec['cron'] %></td>
<td><%= job_spec['class'] %></td>
<td>
<a href="<%= root_path %>queues/<%= job_spec.fetch('queue', 'default') %>"><%= job_spec.fetch('queue', 'default') %></a>
<a href="<%= root_path %>queues/<%= job_spec['queue'] %>"><%= job_spec['queue'] %></a>
</td>
<td><%= job_spec['args'] %></td>
<td>
Expand Down

0 comments on commit 937f0e1

Please sign in to comment.