Navigation Menu

Skip to content

Commit

Permalink
refactored detection code
Browse files Browse the repository at this point in the history
  • Loading branch information
purzelrakete committed Sep 30, 2008
1 parent ced11d1 commit 18549af
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Expand Up @@ -50,7 +50,7 @@ Notice the asynch_moo call to CowWorker. This will call the moo method on the Co

All worker classes must inherit from this class, and be saved in app/workers. The Worker is loaded once, at which point the instance method 'create' is called.

Calling async_my_method on the worker class will trigger background work. This means that the loaded Worker instance will receive a call to the method my_method(:uid => "thisjobsuid2348732947923").
Calling `async_my_method` on the worker class will trigger background work. This means that the loaded Worker instance will receive a call to the method `my_method(:uid => "thisjobsuid2348732947923")`.

## Exception handling in Workers

Expand Down
21 changes: 18 additions & 3 deletions lib/workling.rb
Expand Up @@ -14,11 +14,11 @@ class WorklingNotFoundError < WorklingError; end
# Workling::Remote.dispatcher = Workling::Remote::Runners::StarlingRunner.new
#
def self.default_runner
if Object.const_defined? "Starling"
if starling_installed?
Workling::Remote::Runners::StarlingRunner.new
elsif Object.const_defined? "Spawn" # the spawn plugin is installed.
elsif spawn_installed?
Workling::Remote::Runners::SpawnRunner.new
elsif Object.const_defined? "Bj" # the backgroundjob plugin is installed.
elsif bj_installed?
Workling::Remote::Runners::BackgroundjobRunner.new
else
Workling::Remote::Runners::NotRemoteRunner.new
Expand All @@ -38,6 +38,21 @@ def self.find(clazz, method = nil)
raise_not_found(clazz, method) if method && !inst.respond_to?(method)
inst
end

# is spawn installed?
def self.spawn_installed?
Object.const_defined? "Spawn"
end

# is starling installed?
def self.starling_installed?
Object.const_defined? "Starling"
end

# is bj installed?
def self.bj_installed?
Object.const_defined? "Bj"
end

private
def self.raise_not_found(clazz, method)
Expand Down
2 changes: 1 addition & 1 deletion lib/workling/remote/runners/spawn_runner.rb
Expand Up @@ -6,7 +6,7 @@ module Runners
class SpawnRunner < Workling::Remote::Runners::Base
cattr_accessor :options
@@options = { :method => :fork }
include ::Spawn
include Spawn if Workling.spawn_installed?

def run(clazz, method, options = {})
spawn(SpawnRunner.options) do # exceptions are trapped in here.
Expand Down
6 changes: 3 additions & 3 deletions script/starling_status.rb
Expand Up @@ -2,9 +2,9 @@

puts '=> Loading Rails...'

require File.dirname(__FILE__) + '/../../../../config/environment'
require File.dirname(__FILE__) + '/../lib/workling/starling/poller'
require File.dirname(__FILE__) + '/../lib/workling/starling/routing/class_and_method_routing'
require File.dirname(__FILE__) + '/../config/environment'
require File.dirname(__FILE__) + '/../vendor/plugins/workling/lib/workling/starling/poller'
require File.dirname(__FILE__) + '/../vendor/plugins/workling/lib/workling/starling/routing/class_and_method_routing'

puts '** Rails loaded.'

Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -6,7 +6,7 @@
require 'active_support'
require 'test/spec'
require 'mocha'
gem 'memcache-client'
gem 'fiveruns-memcache-client'
require 'memcache'

$:.unshift plugin_lib, plugin_test
Expand Down

0 comments on commit 18549af

Please sign in to comment.