Skip to content

Commit d36e5df

Browse files
authored
Merge pull request #199 from rails/dispatch-scheduled-and-recurring
Allow enqueuing scheduled jobs and recurring tasks right away
2 parents 0b91e3b + b52b420 commit d36e5df

File tree

24 files changed

+102
-23
lines changed

24 files changed

+102
-23
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ GEM
241241
rack-session (>= 2.0.0, < 3)
242242
tilt (~> 2.0)
243243
smart_properties (1.17.0)
244-
solid_queue (1.0.0)
244+
solid_queue (1.0.1)
245245
activejob (>= 7.1)
246246
activerecord (>= 7.1)
247247
concurrent-ruby (>= 1.3.1)
@@ -306,7 +306,7 @@ DEPENDENCIES
306306
rubocop-performance
307307
rubocop-rails-omakase
308308
selenium-webdriver
309-
solid_queue (~> 1.0)
309+
solid_queue (~> 1.0.1)
310310
sprockets-rails
311311
sqlite3
312312

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ This library extends Active Job with a querying interface and the following sett
6666
## Adapter Specifics
6767

6868
- **Resque**: Queue pausing is supported only if you have `resque-pause` installed in your project
69-
- **Solid Queue**: Requires version >= 0.9.
69+
- **Solid Queue**: Requires version >= 1.0.1.
7070

7171
## Advanced configuration
7272

app/assets/stylesheets/mission_control/jobs/jobs.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ table.jobs {
2525
width: 45%;
2626
}
2727
&.scheduled th.job-header {
28-
width: 60%;
28+
width: 40%;
2929
}
3030
&.finished th.job-header {
3131
width: 65%;

app/controllers/mission_control/jobs/discards_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def create
88

99
private
1010
def jobs_relation
11-
ActiveJob.jobs.failed
11+
ActiveJob.jobs
1212
end
1313

1414
def redirect_location

app/controllers/mission_control/jobs/dispatches_controller.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ class MissionControl::Jobs::DispatchesController < MissionControl::Jobs::Applica
33

44
def create
55
@job.dispatch
6-
redirect_to application_jobs_url(@application, :blocked), notice: "Dispatched job with id #{@job.job_id}"
6+
redirect_to redirect_location, notice: "Dispatched job with id #{@job.job_id}"
77
end
88

99
private
10-
def jobs_relation
11-
ApplicationJob.jobs.blocked
12-
end
10+
def jobs_relation
11+
ActiveJob.jobs
12+
end
13+
14+
def redirect_location
15+
status = @job.status.presence_in(supported_job_statuses) || :blocked
16+
application_jobs_url(@application, status)
17+
end
1318
end

app/controllers/mission_control/jobs/recurring_tasks_controller.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class MissionControl::Jobs::RecurringTasksController < MissionControl::Jobs::ApplicationController
22
before_action :ensure_supported_recurring_tasks
3-
before_action :set_recurring_task, only: :show
3+
before_action :set_recurring_task, only: [ :show, :update ]
44

55
def index
66
@recurring_tasks = MissionControl::Jobs::Current.server.recurring_tasks
@@ -10,6 +10,14 @@ def show
1010
@jobs_page = MissionControl::Jobs::Page.new(@recurring_task.jobs, page: params[:page].to_i)
1111
end
1212

13+
def update
14+
if (job = @recurring_task.enqueue) && job.successfully_enqueued?
15+
redirect_to application_job_path(@application, job.job_id), notice: "Enqueued recurring task #{@recurring_task.id}"
16+
else
17+
redirect_to application_recurring_task_path(@application, @recurring_task), alert: "Something went wrong enqueuing this recurring task"
18+
end
19+
end
20+
1321
private
1422
def ensure_supported_recurring_tasks
1523
unless recurring_tasks_supported?

app/helpers/mission_control/jobs/jobs_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def failed_job_backtrace(job, server)
2626
def attribute_names_for_job_status(status)
2727
case status.to_s
2828
when "failed" then [ "Error", "" ]
29-
when "blocked" then [ "Queue", "Blocked by", "Block expiry", "" ]
29+
when "blocked" then [ "Queue", "Blocked by", "" ]
3030
when "finished" then [ "Queue", "Finished" ]
3131
when "scheduled" then [ "Queue", "Scheduled", "" ]
3232
when "in_progress" then [ "Queue", "Run by", "Running since" ]

app/models/mission_control/jobs/recurring_task.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def jobs
1212
ActiveJob::JobsRelation.new(queue_adapter: queue_adapter).where(recurring_task_id: id)
1313
end
1414

15+
def enqueue
16+
queue_adapter.enqueue_recurring_task(id)
17+
end
18+
1519
private
1620
attr_reader :queue_adapter
1721
end

app/views/mission_control/jobs/jobs/_general_information.html.erb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
<%= formatted_time(job.enqueued_at.to_datetime) %>
2727
</td>
2828
</tr>
29+
<% if job.scheduled? %>
30+
<tr>
31+
<th>Scheduled</th>
32+
<td>
33+
<%= formatted_time(job.scheduled_at) %>
34+
<% if job_delayed?(job) %>
35+
<div class="is-danger tag ml-4">delayed</div>
36+
<% end %>
37+
</td>
38+
</tr>
39+
<% end %>
2940
<% if job.failed? %>
3041
<tr>
3142
<th>Failed</th>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="buttons is-right">
2-
<%= button_to "Dispatch", application_job_dispatch_path(@application, job.job_id), class: "button is-warning is-light mr-0" %>
2+
<%= button_to "Run now", application_job_dispatch_path(@application, job.job_id), class: "button is-warning is-light mr-0" %>
33
</div>

0 commit comments

Comments
 (0)