-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support dispatching blocked jobs directly from the UI
Introduce the dispatch action to blocked jobs Closes #37 Signed-off-by: Lex Cao <[email protected]>
- Loading branch information
Showing
17 changed files
with
97 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/controllers/mission_control/jobs/dispatches_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class MissionControl::Jobs::DispatchesController < MissionControl::Jobs::ApplicationController | ||
include MissionControl::Jobs::JobScoped | ||
|
||
def create | ||
@job.dispatch | ||
redirect_to application_jobs_url(@application, :blocked), notice: "Dispatched job with id #{@job.job_id}" | ||
end | ||
|
||
private | ||
def jobs_relation | ||
ApplicationJob.jobs.blocked | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
app/views/mission_control/jobs/jobs/blocked/_actions.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="buttons is-right"> | ||
<%= button_to "Dispatch", application_job_dispatch_path(@application, job.job_id), class: "button is-warning is-light mr-0" %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<td><%= link_to job.queue_name, application_queue_path(@application, job.queue) %></td> | ||
<td><div class="is-family-monospace is-size-7"><%= job.blocked_by %></div></td> | ||
<td><%= bidirectional_time_distance_in_words_with_title(job.blocked_until) %></td> | ||
<td class="pr-0"> | ||
<%= render "mission_control/jobs/jobs/blocked/actions", job: job %> | ||
</td> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
test/active_job/queue_adapters/adapter_testing/dispatch_jobs.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module ActiveJob::QueueAdapters::AdapterTesting::DispatchJobs | ||
extend ActiveSupport::Testing::Declarative | ||
|
||
test "dispatch blocked job immediately" do | ||
10.times { |index| BlockingJob.perform_later(index * 0.1.seconds) } | ||
|
||
# Given, there is one pending and the others are blocked | ||
pending_jobs = ActiveJob.jobs.pending | ||
assert_equal 1, pending_jobs.size | ||
blocked_jobs = ActiveJob.jobs.blocked | ||
assert_equal 9, blocked_jobs.size | ||
|
||
blocked_jobs.each(&:dispatch) | ||
|
||
# Then, all blocked jobs are pending | ||
assert_empty blocked_jobs.reload | ||
assert_equal 10, pending_jobs.reload.size | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class BlockingJob < ApplicationJob | ||
limits_concurrency key: ->(*args) { "exclusive" } | ||
|
||
def perform(pause = nil) | ||
sleep(pause) if pause | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters