Class: Timberline::AnonymousWorker

Inherits:
Worker
  • Object
show all
Defined in:
lib/timberline/anonymous_worker.rb

Overview

The AnonymousWorker is exactly what it says on the tin - a way to process a queue without defining a new class, by instead just passing in a block that will be executed for each item on the queue as it’s popped.

Instance Method Summary collapse

Methods inherited from Worker

#error_item, #executing_job?, #handle_process_exception, #keep_watching?, #retry_item, #watch

Constructor Details

#initialize(&block) ⇒ AnonymousWorker

Creates a new AnonymousWorker. The block’s binding will be updated to give it access to retry_item and error_item so that the block can easily control the processing flow for queued items.

Examples:

Creating a simple AnonymousWorker

AnonymousWorker.new { |item| puts item.contents }

Parameters:

  • block (Block)

    the block to run against each item that gets popped off the queue.



21
22
23
24
# File 'lib/timberline/anonymous_worker.rb', line 21

def initialize(&block)
  @block = block
  fix_block_binding
end

Instance Method Details

#process_item(item) ⇒ Object

See Also:



28
29
30
# File 'lib/timberline/anonymous_worker.rb', line 28

def process_item(item)
  @block.call(item, self)
end