Class: Nuntius::MessengerJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/nuntius/messenger_job.rb

Instance Method Summary collapse

Instance Method Details

#cleanup_nuntius_eventsObject



23
24
25
26
27
28
# File 'app/jobs/nuntius/messenger_job.rb', line 23

def cleanup_nuntius_events
  Nuntius::Event.where(
    transitionable: arguments.first,
    transition_event: arguments.second.to_s
  ).delete_all
end

#perform(obj, event, params = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/jobs/nuntius/messenger_job.rb', line 8

def perform(obj, event, params = {})
  return unless obj

  ActiveRecord::Base.transaction do
    messenger = Nuntius::BaseMessenger.messenger_for_obj(obj).new(obj, event, params)
    return unless messenger.is_a?(Nuntius::CustomMessenger) || messenger.respond_to?(event.to_sym)

    result = messenger.call
    return if result == false

    templates = messenger.templates
    messenger.dispatch(templates) if templates.exists?
  end
end