Class: Workling::Base
- Inherits:
-
Object
- Object
- Workling::Base
- Defined in:
- lib/workling/base.rb
Class Method Summary collapse
- .inherited(subclass) ⇒ Object
-
.method_missing(method, *args, &block) ⇒ Object
thanks to blaine cook for this suggestion.
Instance Method Summary collapse
-
#create ⇒ Object
Put worker initialization code in here.
-
#dispatch_to_worker_method(method, options) ⇒ Object
takes care of suppressing remote errors but raising Workling::WorklingNotFoundError where appropriate.
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
24 25 26 27 28 |
# File 'lib/workling/base.rb', line 24 def initialize super create end |
Class Method Details
.inherited(subclass) ⇒ Object
20 21 22 |
# File 'lib/workling/base.rb', line 20 def self.inherited(subclass) Workling::Discovery.discovered << subclass end |
.method_missing(method, *args, &block) ⇒ Object
thanks to blaine cook for this suggestion.
51 52 53 54 55 56 57 |
# File 'lib/workling/base.rb', line 51 def self.method_missing(method, *args, &block) if method.to_s =~ /^asynch?_(.*)/ Workling::Remote.run(self.to_s.dasherize, $1, *args) else super end end |
Instance Method Details
#create ⇒ Object
Put worker initialization code in here. This is good for restarting jobs that were interrupted.
32 33 |
# File 'lib/workling/base.rb', line 32 def create end |
#dispatch_to_worker_method(method, options) ⇒ Object
takes care of suppressing remote errors but raising Workling::WorklingNotFoundError where appropriate. swallow workling exceptions so that everything behaves like remote code. otherwise StarlingRunner and SpawnRunner would behave too differently to NotRemoteRunner.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/workling/base.rb', line 38 def dispatch_to_worker_method(method, ) begin self.send(method, ) rescue Exception => e raise e if e.kind_of?(Workling::WorklingError) logger.error "WORKLING ERROR: runner could not invoke #{ self.class }:#{ method } with #{ .inspect }. error was: #{ e.inspect }\n #{ e.backtrace.join("\n") }" # reraise after logging. the exception really can't go anywhere in many cases. (spawn traps the exception) raise e if Workling.raise_exceptions? end end |