-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to pause jobs by queue, job class, or label (experimental) (
#1575) * Add ability to pause jobs by queue or job class (experimental) * Move behavior into pauses controller * Put all the values under a single setting key * Add label as pausable * Only show Dashboard UI when configuration is enabled * Add a number badge to navbar * Remove extraneous changes * Clean up the controller
- Loading branch information
1 parent
81fdbe2
commit 19234ee
Showing
35 changed files
with
1,111 additions
and
78 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
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module GoodJob | ||
class PausesController < ApplicationController | ||
before_action :validate_type, only: [:create, :destroy] | ||
def index | ||
@paused = GoodJob::Setting.paused | ||
end | ||
|
||
def create | ||
pause_type = params[:type].to_sym | ||
pause_value = params[:value].to_s | ||
|
||
GoodJob::Setting.pause(pause_type => pause_value) | ||
redirect_to({ action: :index }, notice: "Successfully paused #{params[:type]} '#{params[:value]}'") | ||
end | ||
|
||
def destroy | ||
pause_type = params[:type].to_sym | ||
pause_value = params[:value].to_s | ||
|
||
GoodJob::Setting.unpause(pause_type => pause_value) | ||
redirect_to({ action: :index }, notice: "Successfully unpaused #{params[:type]} '#{params[:value]}'") | ||
end | ||
|
||
private | ||
|
||
def validate_type | ||
return if params[:type].in?(%w[queue job_class label]) && params[:value].to_s.present? | ||
|
||
raise ActionController::BadRequest, "Invalid type" | ||
end | ||
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
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,28 @@ | ||
<% group = type.to_s.pluralize.to_sym %> | ||
<% items = paused.fetch(group) { [] } %> | ||
<% if items&.any? %> | ||
<div class="my-3 card"> | ||
<div class="list-group list-group-flush text-nowrap" role="table"> | ||
<header class="list-group-item bg-body-tertiary"> | ||
<div class="row small text-muted text-uppercase align-items-center"> | ||
<div class="col-12"><%= t("good_job.pauses.index.#{type}") %></div> | ||
</div> | ||
</header> | ||
|
||
<% items.each do |value| %> | ||
<li class="list-group-item d-flex justify-content-between align-items-center"> | ||
<%= value %> | ||
<%= button_to( | ||
{ action: :destroy, type: type, value: value }, | ||
method: :delete, | ||
class: 'btn btn-sm btn-outline-primary', | ||
data: { confirm: t('good_job.pauses.index.confirm_unpause', value: value) } | ||
) do %> | ||
<%= render_icon "play" %> | ||
<%= t("good_job.pauses.index.unpause") %> | ||
<% end %> | ||
</li> | ||
<% end %> | ||
</div> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<li class="list-group-item d-flex justify-content-between align-items-center"> | ||
<%= value %> | ||
<%= button_to t('good_job.pauses.index.unpause'), | ||
{ action: :destroy, type: type, value: value }, | ||
method: :delete, | ||
class: 'btn btn-sm btn-outline-primary', | ||
data: { confirm: t('good_job.pauses.index.confirm_unpause', value: value) } %> | ||
</li> |
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,46 @@ | ||
<%= content_for :page_title do %> | ||
<%= t('good_job.pauses.index.title') %> | ||
<% end %> | ||
|
||
<div class="border-bottom"> | ||
<h1 class="h2 pt-3 pb-2"><%= t('good_job.pauses.index.title') %></h1> | ||
</div> | ||
|
||
<% if GoodJob.configuration.enable_pauses %> | ||
<div class="card mb-4"> | ||
<div class="card-body"> | ||
<%= form_tag({ action: :create }, method: :post, class: 'row g-3 align-items-end') do %> | ||
<div class="col-3"> | ||
<%= label_tag :type, t('good_job.pauses.index.type'), class: 'form-label' %> | ||
<%= select_tag :type, | ||
options_for_select([ | ||
[t('good_job.pauses.index.queue'), 'queue'], | ||
[t('good_job.pauses.index.job_class'), 'job_class'], | ||
[t('good_job.pauses.index.label'), 'label'], | ||
]), | ||
class: 'form-select', | ||
required: true %> | ||
</div> | ||
<div class="col-6"> | ||
<%= label_tag :value, t('good_job.pauses.index.value'), class: 'form-label' %> | ||
<%= text_field_tag :value, nil, class: 'form-control', autocomplete: "off", required: true %> | ||
</div> | ||
<div class="col-3"> | ||
<%= button_tag type: "submit", class: 'btn btn-primary' do %> | ||
<%= render_icon "pause" %> | ||
<%= t('good_job.pauses.index.pause', value: '') %> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
|
||
<%= render 'group', paused: @paused, type: :queue %> | ||
<%= render 'group', paused: @paused, type: :job_class %> | ||
<%= render 'group', paused: @paused, type: :label %> | ||
<% else %> | ||
<div class="alert alert-warning" role="alert"> | ||
<p><%= t('good_job.pauses.index.disabled') %>:</p> | ||
<pre class="mb-0">config.good_job.enable_pauses = true</pre> | ||
</div> | ||
<% end %> |
Oops, something went wrong.