Class: Pigeon::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/pigeon/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue = nil, context = nil, &filter) ⇒ Processor

Creates a new processor. An optional queue can be specified in which case the processor will register itself as an observer of that queue. A block can be given to filter the tasks contained in the associated queue.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pigeon/processor.rb', line 20

def initialize(queue = nil, context = nil, &filter)
  @id = Pigeon::Support.unique_id
  @filter = filter
  @context = context
  
  if (queue)
    self.queue = queue
  
    switch_to_next_task!
  end
end

Instance Attribute Details

#contextObject

Properties ===========================================================



8
9
10
# File 'lib/pigeon/processor.rb', line 8

def context
  @context
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/pigeon/processor.rb', line 11

def id
  @id
end

#queueObject

Returns the value of attribute queue.



9
10
11
# File 'lib/pigeon/processor.rb', line 9

def queue
  @queue
end

#taskObject (readonly)

Returns the value of attribute task.



10
11
12
# File 'lib/pigeon/processor.rb', line 10

def task
  @task
end

Instance Method Details

#accept?(task) ⇒ Boolean

Returns true if the given task would be accepted by the filter defined for this processor.

Returns:

  • (Boolean)


58
59
60
# File 'lib/pigeon/processor.rb', line 58

def accept?(task)
  !@filter or @filter.call(task)
end

#inspectObject



67
68
69
# File 'lib/pigeon/processor.rb', line 67

def inspect
  "<#{self.class}\##{@id} queue=#{@queue.inspect} task=#{@task} context=#{@context}>"
end

#task?Boolean

Returns true if a task is currently being processed, false otherwise.

Returns:

  • (Boolean)


63
64
65
# File 'lib/pigeon/processor.rb', line 63

def task?
  !!@task
end