public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Added Merb::Worker. You can now add a block to be run in a separate thread
from your merb controllers with the run_later method

run_later do
  SomeBackgroundTask.run
end

The block gets pushed onto a thread safe Queue in the Dispatcher and a
Merb::Worker class has a thread that loops over items in the queue and
calls the block. The work goes to sleep when the queue is empty and wakes
up when items are added to the queue
ezmobius (author)
Mon Jun 23 21:13:05 -0700 2008
commit  ff42997e2a50613d37c40012b4cec623c3cc2fd5
tree    2d01ce2d4e363690d014714cff3431d2f71b17d0
parent  8ceb03e11d386feadfa9dd47b57d72c99e36ee6a
...
544
545
546
547
548
549
550
551
552
...
544
545
546
 
 
 
547
548
549
0
@@ -544,9 +544,6 @@ module Merb
0
       @rakefiles += rakefiles
0
     end
0
 
0
-
0
-
0
-
0
   end
0
 end
0
 
...
18
19
20
 
21
22
23
...
18
19
20
21
22
23
24
0
@@ -18,6 +18,7 @@ module Merb
0
   autoload :Router,                   "merb-core/dispatch/router"
0
   autoload :SessionMixin,             "merb-core/dispatch/session"
0
   autoload :Test,                     "merb-core/test"
0
+  autoload :Worker,                   "merb-core/dispatch/worker"
0
 end
0
 
0
 # Require this rather than autoloading it so we can be sure the default template
...
611
612
613
 
 
 
 
 
 
 
 
614
615
616
...
611
612
613
614
615
616
617
618
619
620
621
622
623
624
0
@@ -611,6 +611,14 @@ class Merb::BootLoader::ChooseAdapter < Merb::BootLoader
0
   end
0
 end
0
 
0
+class Merb::BootLoader::StartWorkerThread < Merb::BootLoader
0
+
0
+  # Choose the Rack adapter/server to use and set Merb.adapter.
0
+  def self.run
0
+    Merb::Worker.new
0
+  end
0
+end
0
+
0
 class Merb::BootLoader::RackUpApplication < Merb::BootLoader
0
   # Setup the Merb Rack App or read a rackup file located at
0
   # Merb::Config[:rackup] with the same syntax as the
...
1
2
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
5
6
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
0
@@ -1,6 +1,22 @@
0
 module Merb
0
   # Module that is mixed in to all implemented controllers.
0
   module ControllerMixin
0
+    
0
+    # Enqueu a block to run in a background thread outside of the request
0
+    # response dispatch
0
+    #
0
+    # ==== Parameters
0
+    # takes a block to run later
0
+    #
0
+    # ==== Example
0
+    # run_later do
0
+    #   SomeBackgroundTask.run
0
+    # end
0
+    #
0
+    def run_later(&blk)
0
+      Merb::Dispatcher.work_queue << blk
0
+    end
0
+    
0
     # Renders the block given as a parameter using chunked encoding.
0
     #
0
     # ==== Parameters
...
6
7
8
 
 
 
 
 
 
9
10
11
...
6
7
8
9
10
11
12
13
14
15
16
17
0
@@ -6,6 +6,12 @@ class Merb::Dispatcher
0
     attr_accessor :use_mutex
0
     
0
     @@mutex = Mutex.new
0
+    @@work_queue = Queue.new
0
+    
0
+    def work_queue 
0
+      @@work_queue
0
+    end  
0
+    
0
     Merb::Dispatcher.use_mutex = ::Merb::Config[:use_mutex]
0
     
0
     # This is where we grab the incoming request REQUEST_URI and use that in

Comments