Skip to content
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

Merged
merged 13 commits into from
Mar 7, 2018

Conversation

takonomura
Copy link
Contributor

@takonomura takonomura commented Jan 22, 2018

Add button to suspend worker. It prevent executing new task on the worker when the worker has suspended.

Kuroko Workers page

Before:
before
After:
after

@eisuke
Copy link
Member

eisuke commented Jan 22, 2018

I feel that it is better to changing Status label to SUSPENDED. What do you think?

@takonomura
Copy link
Contributor Author

I agree. I changed it in 205da11.

@@ -39,3 +42,18 @@
role: 'button', class: 'btn btn-sm btn-default')
- else
' 
td
- if !worker.suspended
= button_to('Suspend',
Copy link
Contributor

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? 🤔

Copy link
Contributor Author

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.

Copy link
Contributor

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) ;)

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks!! XD

@ganmacs
Copy link
Contributor

ganmacs commented Jan 29, 2018

Would you resolve the conflicts?

@takonomura takonomura force-pushed the feature/suspend-worker branch from 2fa5b37 to 94fd0d3 Compare January 29, 2018 02:38
@takonomura
Copy link
Contributor Author

I resolved conflicts by rebasing.

params: { suspended: true },
role: 'button',
class: 'btn btn-xs btn-default',
data: { confirm: 'Continue suspending the worker? If not, use "Cancel" button.' })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nits] "If not, use "Cancel" button" sounds too obvious to me

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update_column skips varidations and callbacks and doesn't update updated_at. Why did you choose update_column instead of update! ?
http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-update_column

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first_or_initialize! method doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I fixed in 34839bc.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first_or_initialize doesn't create a new record, is it? Did you try command-executor locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did. first_or_initialize doesn't create a new record, but update! at next line create a new record if not exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Worker.where(...).first_or_create!(suspendable: true) ?
I cloudn't get the reason why you split into first_or_initialize + update!.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worker.where(...).first_or_create!(suspendable: true) creates a new record with suspendable: true, but doesn't update an existing record if the record has suspendable: false.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but I think creating a new record by update! is confusing

@eisuke eisuke merged commit 8654220 into cookpad:master Mar 7, 2018
@takonomura takonomura deleted the feature/suspend-worker branch April 13, 2018 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants