Class: GirlFriday::WorkQueue
- Inherits:
-
Object
- Object
- GirlFriday::WorkQueue
- Defined in:
- lib/girl_friday/work_queue.rb
Defined Under Namespace
Classes: Ready, Shutdown, Work
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, options = {}, &block) ⇒ WorkQueue
constructor
A new instance of WorkQueue.
- #push(work, &block) ⇒ Object (also: #<<)
- #shutdown ⇒ Object
- #status ⇒ Object
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, ={}, &block) @name = name.to_s @size = [:size] || 5 @processor = block @error_handler = ([:error_handler] || ErrorHandler.default).new @shutdown = false @busy_workers = [] @created_at = Time.now.to_i @total_processed = @total_errors = @total_queued = 0 @persister = ([:store] || Store::InMemory).new(name, ([:store_config] || [])) start GirlFriday.queues << WeakRef.new(self) end |
Instance Attribute Details
#name ⇒ Object (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 |
#shutdown ⇒ Object
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 |
#status ⇒ Object
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 |