Parent

GirlFriday::WorkQueue

Constants

Ready
Shutdown
Work

Attributes

name[R]

Public Class Methods

immediate!() click to toggle source
# File lib/girl_friday/work_queue.rb, line 28
def self.immediate!
  alias_method :push, :push_immediately
  alias_method :<<, :push_immediately
end
new(name, options={}, &block) click to toggle source
# File lib/girl_friday/work_queue.rb, line 9
def initialize(name, options={}, &block)
  raise ArgumentError, "#{self.class.name} requires a block" unless block_given?
  @name = name.to_s
  @size = options[:size] || 5
  @processor = block
  @error_handlers = (Array(options[:error_handler] || ErrorHandler.default)).map(&:new)

  @shutdown = false
  @shutting_down = false
  @busy_workers = []
  @ready_workers = nil
  @created_at = Time.now.to_i
  @total_processed = @total_errors = @total_queued = 0
  @persister = (options[:store] || Store::InMemory).new(name, (options[:store_config] || {}))
  @weakref = WeakRef.new(self)
  start
  GirlFriday.add_queue @weakref
end
queue!() click to toggle source
# File lib/girl_friday/work_queue.rb, line 33
def self.queue!
  alias_method :push, :push_async
  alias_method :<<, :push_async
end

Public Instance Methods

<<(work, &block) click to toggle source
Alias for: push_async
push(work, &block) click to toggle source
Alias for: push_async
push_async(work, &block) click to toggle source
# File lib/girl_friday/work_queue.rb, line 44
def push_async(work, &block)
  @supervisor << Work[work, block]
end
Also aliased as: push, <<
push_immediately(work, &block) click to toggle source
# File lib/girl_friday/work_queue.rb, line 38
def push_immediately(work, &block)
  result = @processor.call(work)
  return yield result if block
  result
end
shutdown(&block) click to toggle source
# File lib/girl_friday/work_queue.rb, line 74
def shutdown(&block)
  # Runtime state should never be modified by caller thread,
  # only the Supervisor thread.
  @supervisor << Shutdown[block]
end
status() click to toggle source
# File lib/girl_friday/work_queue.rb, line 50
def status
  { @name => {
      :pid => $$,
      :pool_size => @size,
      :ready => @ready_workers ? @ready_workers.size : 0,
      :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
wait_for_empty() click to toggle source

Busy wait for the queue to empty. Useful for testing.

# File lib/girl_friday/work_queue.rb, line 68
def wait_for_empty
  until @persister.size == 0
    sleep 0.1
  end
end
working?() click to toggle source
# File lib/girl_friday/work_queue.rb, line 80
def working?
  @busy_workers.size > 0
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.