Class: GirlFriday::WorkQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/girl_friday/work_queue.rb

Defined Under Namespace

Classes: Ready, Shutdown, Work

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ WorkQueue

Returns a new instance of WorkQueue.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/girl_friday/work_queue.rb', line 10

def initialize(name, options={}, &block)
  @name = name.to_s
  @size = options[:size] || 5
  @processor = block
  @error_handler = (options[:error_handler] || ErrorHandler.default).new

  @shutdown = false
  @busy_workers = []
  @created_at = Time.now.to_i
  @total_processed = @total_errors = @total_queued = 0
  @persister = (options[:store] || Store::InMemory).new(name, (options[:store_config] || []))
  start
  GirlFriday.queues << WeakRef.new(self)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/girl_friday/work_queue.rb', line 9

def name
  @name
end

Instance Method Details

#push(work, &block) ⇒ Object Also known as: <<



25
26
27
# File 'lib/girl_friday/work_queue.rb', line 25

def push(work, &block)
  @supervisor << Work[work, block]
end

#shutdownObject



46
47
48
49
50
# File 'lib/girl_friday/work_queue.rb', line 46

def shutdown
  # Runtime state should never be modified by caller thread,
  # only the Supervisor thread.
  @supervisor << Shutdown[block_given? ? Proc.new : nil]
end

#statusObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/girl_friday/work_queue.rb', line 30

def status
  { @name => {
      :pid => $$,
      :pool_size => @size,
      :ready => ready_workers.size,
      :busy => @busy_workers.size,
      :backlog => @persister.size,
      :total_queued => @total_queued,
      :total_processed => @total_processed,
      :total_errors => @total_errors,
      :uptime => Time.now.to_i - @created_at,
      :created_at => @created_at,
    }
  }
end