Skip to content

Commit

Permalink
Expose the stage controller thread
Browse files Browse the repository at this point in the history
  • Loading branch information
methodmissing committed Feb 15, 2009
1 parent f8d613f commit e349d00
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/scrooge/framework/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def middleware
#
def install_tracking_middleware
GUARD.synchronize do
#ActionController::Dispatcher.to_prepare( :scrooge_install_tracking_middleware ) do
ActionController::Dispatcher.to_prepare( :scrooge_install_tracking_middleware ) do
ApplicationController.prepend_around_filter Scrooge::Middleware::Tracker
#end
end
end
end

Expand All @@ -75,12 +75,12 @@ def uninstall_tracking_middleware
#
def install_scope_middleware( tracker )
GUARD.synchronize do
#ActionController::Dispatcher.to_prepare( :scrooge_install_scope_middleware ) do
ActionController::Dispatcher.to_prepare( :scrooge_install_scope_middleware ) do
tracker.resources.each do |resource|
install_scope_middleware_for_resource!( resource )
end
end
#end
end
end

def initialized( &block )
Expand Down
4 changes: 3 additions & 1 deletion lib/scrooge/strategy/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class NoStages < StandardError
@@stages = Hash.new( [] )
@@stages[self.name] = []

attr_reader :thread

class << self

# Stage definition macro.
Expand Down Expand Up @@ -62,7 +64,7 @@ def stages
# Enforce this strategy
#
def execute!
Scrooge::Strategy::Controller.new( self ).run!
@thread = Scrooge::Strategy::Controller.new( self ).run!
end

end
Expand Down
3 changes: 2 additions & 1 deletion lib/scrooge/strategy/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ module Strategy
class Controller

attr_accessor :strategy
attr_reader :thread

def initialize( strategy )
@strategy = strategy
end

def run!
Thread.new do
@thread = Thread.new do
Thread.current.abort_on_exception = true
stages.map do |stage|
stage.execute!
Expand Down
1 change: 0 additions & 1 deletion lib/scrooge/tracker/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def inspect
#
def filter( controller, &block )
#{model.model.to_s}.#{profile.orm.resource_scope_method( resource ).to_s} do
Scrooge::Base.profile.log "Scope for Model #{model.inspect}"
block.call
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/units/scrooge/strategy/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@
@base.stages.first.class.should eql( Scrooge::Strategy::Stage )
end

it "should be able to execute itself" do
@base.execute!().class.should == Thread
end

it "should provide access to it's controller Thread" do
@base.execute!
@base.thread.class.should == Thread
end

end
5 changes: 5 additions & 0 deletions spec/units/scrooge/strategy/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@
@controller.run!().value.should include( 'payload' )
end

it "should be able to provide access to the background thread" do
@controller.run!()
@controller.thread.class.should == Thread
end

end

0 comments on commit e349d00

Please sign in to comment.