From ec2e45f0e7162ff54f81ba97ddddf948dcf5b1bd Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Mon, 27 Aug 2018 15:46:48 -0700 Subject: [PATCH 1/2] create new notification types for request completion --- db/fixtures/notification_types.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/db/fixtures/notification_types.yml b/db/fixtures/notification_types.yml index d2c7b9b4116..c179138c213 100644 --- a/db/fixtures/notification_types.yml +++ b/db/fixtures/notification_types.yml @@ -39,6 +39,17 @@ :expires_in: 14.days :level: :warning :audience: group +- :name: transformation_plan_request_succeeded + :message: Plan %{plan_name} has completed successfully + :expires_in: 14.days + :level: :success + :audience: global +- :name: transformation_plan_request_failed + :message: Plan %{plan_name} has completed with errors + :expires_in: 14.days + :level: :error + :audience: global + :link_to: "subject" - :name: automate_user_success :message: '%{message}' :expires_in: 24.hours From 70f33e15a4d72e8c6ac777d3ce8777d467d35866 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Mon, 27 Aug 2018 15:51:39 -0700 Subject: [PATCH 2/2] emit notifications when a request completes --- .../service_template_transformation_plan_request.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/service_template_transformation_plan_request.rb b/app/models/service_template_transformation_plan_request.rb index 53d22b034f7..8a3c38c085a 100644 --- a/app/models/service_template_transformation_plan_request.rb +++ b/app/models/service_template_transformation_plan_request.rb @@ -28,4 +28,13 @@ def cancel update_attributes(:cancelation_status => MiqRequest::CANCEL_STATUS_REQUESTED) miq_request_tasks.each(&:cancel) end + + def update_request_status + super + if request_state == 'finished' && status == 'Ok' + Notification.create(:type => "transformation_plan_request_succeeded", :options => {:plan_name => description}) + elsif request_state == 'finished' && status != 'Ok' + Notification.create(:type => "transformation_plan_request_failed", :options => {:plan_name => description}, :subject => self) + end + end end