Skip to content
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

Fix presentation of the Queue in the Recurring Jobs page #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
10 changes: 9 additions & 1 deletion lib/sidecloq/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this should be in the from_hash function in the Schedule class, so that this behavior is consistent even outside of this view?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(i'm also wondering if we need to also support ActiveJob's queue_as

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly? However, this code explicitly calls from_redis, so it appears to be redis specific to begin with (not sure why, just noting the observation)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, true. but makes me think this logic should be in the schedule class... iow -- there seems to be some manipulation of the state of the schedule before display, such as the queue, so that logic either is duplicated somewhere or what's being displayed isn't matching what's actually being done (like the queue). (one other option is that i just haven't had enough ☕ )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change to refactor into the from_hash method might be a bit out of my depth as I'm not as familiar with the code base. I'm wondering if it makes sense to merge this PR as is, since it fixes the problem, and then a follow up could be done to refactor into from_hash

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
Loading