Parent

Class Index [+]

Quicksearch

Merb::Worker

Attributes

thread[RW]

:api: private

Public Class Methods

alive?() click to toggle source

Returns

Whether the Merb::Worker instance thread is alive

:api: private

    # File lib/merb-core/dispatch/worker.rb, line 37
37:       def alive?
38:         started? and @worker.thread.alive?
39:       end
new() click to toggle source

Creates a new worker thread that loops over the work queue.

:api: private

    # File lib/merb-core/dispatch/worker.rb, line 60
60:     def initialize
61:       @thread = Thread.new do
62:         loop do
63:           process_queue
64:           break if Merb::Dispatcher.work_queue.empty? && Merb.exiting
65:         end
66:       end
67:     end
restart() click to toggle source

restarts the worker thread

Returns

Merb::Worker

instance of a worker.

:api: private

    # File lib/merb-core/dispatch/worker.rb, line 47
47:       def restart
48:         # if we have a worker or thread, kill it.
49:         if started?
50:           @worker.thread.exit
51:           @worker = nil
52:         end
53:         start
54:       end
start() click to toggle source

Returns

Merb::Worker

instance of a worker.

:api: private

    # File lib/merb-core/dispatch/worker.rb, line 12
12:       def start
13:         @worker ||= new
14:         Merb.at_exit do 
15:           if Merb::Dispatcher.work_queue.empty?
16:             @worker.thread.abort_on_exception = false
17:             @worker.thread.raise
18:           else
19:             @worker.thread.join
20:           end
21:         end
22:         @worker
23:       end
started?() click to toggle source

Returns

Whether the Merb::Worker instance is already started.

:api: private

    # File lib/merb-core/dispatch/worker.rb, line 29
29:       def started?
30:         !@worker.nil?
31:       end

Public Instance Methods

process_queue() click to toggle source

Processes tasks in the Merb::Dispatcher.work_queue.

:api: private

    # File lib/merb-core/dispatch/worker.rb, line 72
72:     def process_queue
73:       begin
74:         while blk = Merb::Dispatcher.work_queue.pop
75:            # we've been blocking on the queue waiting for an item sleeping.
76:            # when someone pushes an item it wakes up this thread so we 
77:            # immediately pass execution to the scheduler so we don't 
78:            # accidentally run this block before the action finishes 
79:            # it's own processing
80:           Thread.pass
81:           blk.call
82:           break if Merb::Dispatcher.work_queue.empty? && Merb.exiting
83:         end
84:       rescue Exception => e
85:         Merb.logger.warn! %Worker Thread Crashed with Exception:\n#{Merb.exception(e)}\nRestarting Worker Thread!
86:         retry
87:       end
88:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.