Module: Changeling::Async::Trackling

Defined in:
lib/changeling/async/trackling.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/changeling/async/trackling.rb', line 4

def self.included(base)
  base.after_update :async_save_logling
end

Instance Method Details

#async_save_loglingObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/changeling/async/trackling.rb', line 8

def async_save_logling
  unless defined?(Sidekiq) || defined?(Resque)
    raise Changeling::Exceptions::AsyncGemRequired
  end

  if self.changes && !self.changes.empty?
    logling = Changeling::Models::Logling.new(self)

    if defined?(Sidekiq)
      Changeling::Async::SidekiqWorker.perform_async(logling.to_indexed_json)
    elsif defined?(Resque)
      Resque.enqueue(Changeling::Async::ResqueWorker, logling.to_indexed_json)
    end
  end

  true
end