Skip to content

Commit

Permalink
Merge pull request #17835 from skateman/generic-task-notifications
Browse files Browse the repository at this point in the history
Create generic task notifications
  • Loading branch information
agrare authored Aug 24, 2018
2 parents f1ee798 + b936ca8 commit f64fa80
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/models/mixins/notification_mixin.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions db/fixtures/notification_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f64fa80

Please sign in to comment.