From 2fd2c9a949c926bc27d2a970b1e79028a4d8aa8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Hal=C3=A1sz?= Date: Fri, 10 Aug 2018 13:13:35 +0200 Subject: [PATCH 1/2] Create generic task notification types --- db/fixtures/notification_types.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/db/fixtures/notification_types.yml b/db/fixtures/notification_types.yml index 535dff349a2..d2c7b9b4116 100644 --- a/db/fixtures/notification_types.yml +++ b/db/fixtures/notification_types.yml @@ -289,3 +289,23 @@ :expires_in: 24.hours :level: error :audience: global +- :name: generic_task_start + :message: '%{message}' + :expires_in: 7.days + :level: success + :audience: user +- :name: generic_task_finish + :message: '%{message}' + :expires_in: 7.days + :level: success + :audience: user +- :name: generic_task_fail + :message: '%{message}' + :expires_in: 7.days + :level: error + :audience: user +- :name: generic_task_update + :message: '%{message}' + :expires_in: 7.days + :level: success + :audience: user From b936ca8f28d4012416cf9d9047aa58b85d78fc19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Hal=C3=A1sz?= Date: Mon, 13 Aug 2018 10:47:12 +0200 Subject: [PATCH 2/2] Add NotificationMixin for emitting generic task status notifications --- app/models/mixins/notification_mixin.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/models/mixins/notification_mixin.rb diff --git a/app/models/mixins/notification_mixin.rb b/app/models/mixins/notification_mixin.rb new file mode 100644 index 00000000000..7c6e1217e29 --- /dev/null +++ b/app/models/mixins/notification_mixin.rb @@ -0,0 +1,25 @@ +module NotificationMixin + extend ActiveSupport::Concern + + def notify_task_start(message, user_id, subject = self) + notify_task_emit(:generic_task_start, message, user_id, subject) + end + + def notify_task_finish(message, user_id, subject = self) + notify_task_emit(:generic_task_finish, message, user_id, subject) + end + + def notify_task_fail(message, user_id, subject = self) + notify_task_emit(:generic_task_fail, message, user_id, subject) + end + + def notify_task_update(message, user_id, subject = self) + notify_task_emit(:generic_task_update, message, user_id, subject) + end + + private + + def notify_task_emit(type, message, user_id, subject) + Notification.create(:type => type, :subject => subject, :user_id => user_id, :options => {:message => message}) + end +end