-
Notifications
You must be signed in to change notification settings - Fork 72
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
Add button to suspend worker #94
Changes from 11 commits
fd80695
69abbd7
d9d98b0
77e281f
14233ef
bcdbefa
b0d1f94
2797eff
92fe6ce
88fcc64
94fd0d3
9a97ff2
34839bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
class Kuroko2::WorkersController < Kuroko2::ApplicationController | ||
before_action :set_worker, only: %i(update) | ||
|
||
def index | ||
@workers = Kuroko2::Worker.ordered.all | ||
end | ||
|
||
def update | ||
@worker.update_attributes(worker_params) | ||
redirect_to workers_path | ||
end | ||
|
||
private | ||
|
||
def set_worker | ||
@worker = Kuroko2::Worker.find(params[:id]) | ||
end | ||
|
||
def worker_params | ||
params.permit(:suspended) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,18 @@ | |
th.col-md-1 WID | ||
th.col-md-2 Queue | ||
th.col-md-1 Status | ||
th.col-md-5 Execution | ||
th.col-md-4 Execution | ||
th.col-md-1 | ||
th.col-md-1 | ||
- for worker in @workers | ||
tr | ||
td= worker.hostname | ||
td= worker.worker_id | ||
td= worker.queue | ||
td | ||
- if worker.working | ||
- if worker.suspended | ||
span.label.label-warning SUSPENDED | ||
- elsif worker.working | ||
span.label.label-primary WORKING | ||
- else | ||
' | ||
|
@@ -39,3 +42,22 @@ | |
role: 'button', class: 'btn btn-sm btn-default') | ||
- else | ||
' | ||
td | ||
- if !worker.suspendable | ||
' | ||
- elsif !worker.suspended | ||
= button_to('Suspend', | ||
worker_path(worker), | ||
method: :patch, | ||
params: { suspended: true }, | ||
role: 'button', | ||
class: 'btn btn-xs btn-default', | ||
data: { confirm: 'Continue suspending the worker? If not, use "Cancel" button.' }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nits] "If not, use "Cancel" button" sounds too obvious to me |
||
- else | ||
= button_to('Unsuspend', | ||
worker_path(worker), | ||
method: :patch, | ||
params: { suspended: false }, | ||
role: 'button', | ||
class: 'btn btn-xs btn-default', | ||
data: { confirm: 'Continue unsuspending the worker? If not, use "Cancel" button.' }) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddSuspendedToWorkers < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :workers, :suspendable, :boolean, default: false, null: false, after: :execution_id | ||
add_column :workers, :suspended, :boolean, default: false, null: false, after: :suspendable | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,8 @@ def initialize | |
elsif worker_id == (Command::Executor.num_workers - 1) | ||
Command::Monitor.new(hostname: @hostname, worker_id: worker_id) | ||
else | ||
@worker = Worker.where(hostname: @hostname, worker_id: worker_id, queue: @queue).first_or_create! | ||
@worker = Worker.where(hostname: @hostname, worker_id: worker_id, queue: @queue).first_or_initialize! | ||
@worker.update_column(:suspendable, true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I fixed in 34839bc. |
||
Command::Shell.new(hostname: @hostname, worker_id: worker_id, worker: @worker, queue: @queue) | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
sequence(:worker_id) | ||
queue "@default" | ||
working true | ||
suspendable true | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) how about give confirm dialog to user? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If user suspend worker accidentally, the user can unsuspend the worker. So I think confirm dialog is unneeded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my case, I don't want to suspend a worker accidentally, even though I know I can restore it with only one click. anyway, that's not a big problem(why I tagged
nit
) ;)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand. I added confirm dialog in eb5520e.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks!! XD