Skip to content

Commit

Permalink
Merge pull request rails#33 from basecamp/solid-queue-features
Browse files Browse the repository at this point in the history
Order scheduled jobs by scheduled date first and warn about delayed ones
  • Loading branch information
rosa authored Jan 29, 2024
2 parents 12c2cae + d3232e4 commit bfcf651
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/views/mission_control/jobs/jobs/scheduled/_job.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<td><%= link_to job.queue_name, application_queue_path(@application, job.queue) %></td>
<td><%= bidirectional_time_distance_in_words_with_title(job.scheduled_at) %></td>
<td>
<%= bidirectional_time_distance_in_words_with_title(job.scheduled_at) %>
<% if job.scheduled_at.before? 1.minute.ago %>
<div class="is-danger tag ml-4">delayed</div>
<% end %>
</td>
15 changes: 14 additions & 1 deletion lib/active_job/queue_adapters/solid_queue_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def deserialize_and_proxy_solid_queue_job(solid_queue_job, job_status = nil)
job.blocked_until = solid_queue_job&.blocked_execution&.expires_at if job_status == :blocked
job.worker_id = solid_queue_job&.claimed_execution&.process_id if job_status == :in_progress
job.started_at = solid_queue_job&.claimed_execution&.created_at if job_status == :in_progress
job.scheduled_at = solid_queue_job.scheduled_at
end
end

Expand Down Expand Up @@ -160,7 +161,7 @@ def initialize(jobs_relation)
end

def jobs
solid_queue_status.finished? ? finished_jobs.order(finished_at: :desc) : executions.order(:job_id).map(&:job)
solid_queue_status.finished? ? order_finished_jobs(finished_jobs) : order_executions(executions).map(&:job)
end

def count
Expand Down Expand Up @@ -203,6 +204,18 @@ def finished_jobs
.then { |jobs| offset(jobs) }
end

def order_finished_jobs(jobs)
jobs.order(finished_at: :desc)
end

def order_executions(executions)
# Follow polling order for scheduled executions, the rest by job_id
if solid_queue_status.scheduled? then executions.ordered
else
executions.order(:job_id)
end
end

def matches_relation_filters?(job)
matches_status?(job) && matches_queue_name?(job)
end
Expand Down
13 changes: 13 additions & 0 deletions test/controllers/jobs_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,17 @@ class MissionControl::Jobs::JobsControllerTest < ActionDispatch::IntegrationTest
get mission_control_jobs.application_job_url(@application, @job.job_id + "0", filter: { queue_name: "queue_1" })
assert_redirected_to mission_control_jobs.application_queue_path(@application, :queue_1)
end

test "get scheduled jobs" do
DummyJob.set(wait: 3.minutes).perform_later
DummyJob.set(wait: 1.minute).perform_later

travel_to 2.minutes.from_now

get mission_control_jobs.application_jobs_url(@application, :scheduled)

assert_select "tr.job", 2
assert_select "tr.job", /DummyJob\s+Enqueued 2 minutes ago\s+queue_1\s+in 1 minute/
assert_select "tr.job", /DummyJob\s+Enqueued 2 minutes ago\s+queue_1\s+less than a minute ago/
end
end

0 comments on commit bfcf651

Please sign in to comment.