Class: Magent::AsyncChannel

Inherits:
GenericChannel show all
Defined in:
lib/magent/async_channel.rb

Instance Attribute Summary

Attributes inherited from GenericChannel

#name

Instance Method Summary collapse

Methods inherited from GenericChannel

#collection, #dequeue, #enqueue, #initialize, #message_count, #next_message, #queue_count

Methods included from Failure

#enqueue_error, #error_collection, #error_count, #errors, #failed, #remove_error, #retry_error

Constructor Details

This class inherits a constructor from Magent::GenericChannel

Instance Method Details

#process!(message) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/magent/async_channel.rb', line 13

def process!(message)
  klass, id, method_chain = message

  return false if method_chain.nil?

  target = resolve_target(klass, id)

  method_chain.each do |c|
    target = target.send(c[0], *c[1])
  end

  true
end

#push(target, method_chain, priority) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/magent/async_channel.rb', line 3

def push(target, method_chain, priority)
  if target.kind_of?(Class)
    enqueue([target.to_s, nil, method_chain], priority)
  elsif target.class.respond_to?(:find) && target.respond_to?(:id)
    enqueue([target.class.to_s, target.id, method_chain], priority)
  else
    raise ArgumentError, "I don't know how to handle #{target.inspect}"
  end
end