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

Notify when back to normal #93

Merged
merged 8 commits into from
Jan 26, 2018

Conversation

takonomura
Copy link
Contributor

@takonomura takonomura commented Jan 19, 2018

Notify when retried job finished.

@ganmacs
Copy link
Contributor

ganmacs commented Jan 19, 2018

@cookpad/dev-infra review please

@@ -73,7 +73,7 @@ def notify_critical
end

def notify_finished
if @definition.hipchat_notify_finished?
if @definition.hipchat_notify_finished? || @instance.notify_back_to_normal?
message = build_message(level: 'SUCCESS', text: message_builder.finished_text)
Copy link
Member

Choose a reason for hiding this comment

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

I think that it would be better to change message text.

@@ -80,7 +80,7 @@ def notify_critical
end

def notify_finished
if @definition.hipchat_notify_finished?
if @definition.hipchat_notify_finished? || @instance.notify_back_to_normal?
send_attachment_message_to_slack(
level: 'SUCCESS',
text: message_builder.finished_text,
Copy link
Member

Choose a reason for hiding this comment

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

(ditto) I think that it would be better to change message text.

@@ -0,0 +1,6 @@
class AddNotifyBackToNormal < ActiveRecord::Migration[5.1]
def change
add_column :job_definitions, :notify_back_to_normal, :boolean
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 adding after: :notify_cancellation ?

@@ -25,7 +25,7 @@ def retry(token)
node = extract_node(token)

message = "(token #{token.uuid}) Retry current node: '#{node.type}: #{node.option}'"
token.job_instance.update_column(:error_at, nil)
token.job_instance.update_columns(error_at: nil, retrying: true)
Copy link
Member

Choose a reason for hiding this comment

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

If some tasks exists,

eg.

my_runner:  first_task
my_runner:  second_task
  1. a first task has an error.
  2. a first task retried and finished successfully.
  3. Notified back to normal
  4. a second task finished successfully
  5. Notified back to normal

The No.5 notification is not necessary.

Further, the fork task and parallel_fork task are more complicated. It will not work we want with this implementation.
https://github.com/cookpad/kuroko2/blob/master/docs/tasks.md#fork
https://github.com/cookpad/kuroko2/blob/master/docs/tasks.md#parallel_fork

I think that it is better to set retrying status in tokens.context.

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 it in c5246f2.

@takonomura takonomura force-pushed the feature/notify-back-to-normal branch from db9d444 to c5246f2 Compare January 19, 2018 08:56
@@ -119,6 +120,7 @@ def process_next(node, token)
token.mark_as_finished
unless token.parent
token.job_instance.touch(:finished_at)
Notifier.notify(:back_to_normal, token.job_instance) if token.context['RETRYING']
Copy link
Member

Choose a reason for hiding this comment

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

Don't you need deleting the RETRYING context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

token will be destroyed at line 125. So I decided there was no need to delete the RETRYING context.

Copy link
Member

Choose a reason for hiding this comment

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

That's right (I forgot). That seems to be OK.

Copy link
Member

Choose a reason for hiding this comment

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

Oh..., execuse me.
https://github.com/cookpad/kuroko2/pull/93/files#diff-f7b019ffd787516ae6ba13584edcd76dR121
It is necessary to put it outside the above conditions.

Copy link
Member

@eisuke eisuke left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -119,6 +120,7 @@ def process_next(node, token)
token.mark_as_finished
unless token.parent
token.job_instance.touch(:finished_at)
Notifier.notify(:back_to_normal, token.job_instance) if token.context['RETRYING']
Notifier.notify(:finished, token.job_instance)
Copy link
Member

Choose a reason for hiding this comment

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

When retried, should "finished" notification be sent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is necessary for when the job has enabled Notify all event to Slack/Hipchat/Webhook and disabled Notify when back to normal option.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sending both "back to normal" and "finish" notification with checking" notification is duplicated when the job is enabled both "Notify all event to Slack/Hipchat/Webhook" and " Notify when back to normal", isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I understand. I fixed it in 370977b.

@@ -20,6 +20,10 @@ def launched_text
"Launched '#{@definition.name}'"
end

def back_to_normal_text
"Back to normal the current task in '#{@definition.name}'"
Copy link
Member

Choose a reason for hiding this comment

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

"The task in '#{@definition.name}' was successfully retried" is easier to understand I think.

@@ -119,6 +120,7 @@ def process_next(node, token)
token.mark_as_finished
unless token.parent
token.job_instance.touch(:finished_at)
Notifier.notify(:back_to_normal, token.job_instance) if token.context['RETRYING']
Copy link
Member

Choose a reason for hiding this comment

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

Oh..., execuse me.
https://github.com/cookpad/kuroko2/pull/93/files#diff-f7b019ffd787516ae6ba13584edcd76dR121
It is necessary to put it outside the above conditions.

@takonomura takonomura changed the title Add option to notify when back to normal Notify when back to normal Jan 24, 2018
Copy link
Contributor

@ganmacs ganmacs left a comment

Choose a reason for hiding this comment

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

LGTM

@ganmacs
Copy link
Contributor

ganmacs commented Jan 26, 2018

Thanks 👍

@ganmacs ganmacs merged commit b61d296 into cookpad:master Jan 26, 2018
@takonomura takonomura deleted the feature/notify-back-to-normal branch January 29, 2018 06:24
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.

4 participants