Skip to content

Commit

Permalink
Add NotificationMixin for emitting generic task status notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Aug 13, 2018
1 parent f4c9c60 commit 9fba984
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/models/mixins/notification_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module NotificationMixin
extend ActiveSupport::Concern

def notify_task_start(subject, message)
notify_task_emit(:generic_task_start, subject, message)
end

def notify_task_finish(subject, message)
notify_task_emit(:generic_task_finish, subject, message)
end

def notify_task_fail(subject, message)
notify_task_emit(:generic_task_fail, subject, message)
end

def notify_task_update(subject, message)
notify_task_emit(:generic_task_update, subject, message)
end

private

def notify_task_emit(type, subject, message)
subject = self if subject.nil? # Fall back to the model as subject if nil
Notification.create(type, :subject => subject, :options => {:message => message})
end
end

0 comments on commit 9fba984

Please sign in to comment.