Class: Minion::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/mb-minion/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json = "{}", header = nil) ⇒ Message

Returns a new instance of Message.



8
9
10
11
12
13
14
# File 'lib/mb-minion/message.rb', line 8

def initialize json="{}", header=nil
  data = decode(json)
  @headers   = [header]
  @callbacks = data['callbacks']
  @content   = data['content']
  @batch     = data['batch'] || []
end

Instance Attribute Details

#batchObject

Returns the value of attribute batch.



5
6
7
# File 'lib/mb-minion/message.rb', line 5

def batch
  @batch
end

#callbacksObject

Returns the value of attribute callbacks.



5
6
7
# File 'lib/mb-minion/message.rb', line 5

def callbacks
  @callbacks
end

#contentObject

Returns the value of attribute content.



5
6
7
# File 'lib/mb-minion/message.rb', line 5

def content
  @content
end

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/mb-minion/message.rb', line 5

def headers
  @headers
end

Instance Method Details

#<<(data) ⇒ Object



16
17
18
# File 'lib/mb-minion/message.rb', line 16

def << data
  @content << data
end

#callbackObject

Enqueue a job for the next callback in the chain

Returns:

  • void



23
24
25
26
27
28
29
# File 'lib/mb-minion/message.rb', line 23

def callback
  headers.clear
  if callbacks and not callbacks.empty?
    queue_name = callbacks.shift
    Minion.enqueue(queue_name, as_json)
  end
end