Class: Minion::Handler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue_name, block, options = {}) ⇒ Handler

Instantiate the new handler. Takes a queue name and optional lambda to determine conditionally if a queue is subscribable.

Examples:

Create the new handler.

Handler.new("minion.test")

Parameters:

  • queue_name (String)

    The name of the queue.

  • (Hash)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :when (lambda)

    The block for conditionally subscribing.

  • :batch_size (fixnum)

    The number of elements per batch

  • :map (symbol)

    The type of map operation: fanout or reduce

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
# File 'lib/mb-minion/handler.rb', line 27

def initialize(queue_name, block, options = {})
  @queue_name, @block = queue_name, block
  @subscribable = options[:when]
  @batch_size = options[:batch_size]
  @wait = options[:wait] || false
  raise ArgumentError, "wait parameter makes no sense without a batch_size" if (@wait && ! @batch_size)
end

Instance Attribute Details

#batch_sizeObject (readonly)

Returns the value of attribute batch_size.



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

def batch_size
  @batch_size
end

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



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

def queue_name
  @queue_name
end

#waitObject (readonly)

Returns the value of attribute wait.



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

def wait
  @wait
end

Instance Method Details

#executeObject

Executes the handler. Will subscribe to a queue or unsubscribe to it depending on the conditions.

Examples:

Execute the handler.

handler.execute


12
13
14
# File 'lib/mb-minion/handler.rb', line 12

def execute
  subscribable? ? subscribe : unsubscribe
end