Class: Bg::DrbRunner
- Inherits:
-
Object
- Object
- Bg::DrbRunner
- Defined in:
- lib/bg/drb_runner.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(logfile: logfile) ⇒ DrbRunner
constructor
A new instance of DrbRunner.
- #ready? ⇒ Boolean
- #run(proc: nil, args: []) ⇒ Object
Constructor Details
#initialize(logfile: logfile) ⇒ DrbRunner
Returns a new instance of DrbRunner.
9 10 11 |
# File 'lib/bg/drb_runner.rb', line 9 def initialize(logfile: logfile) @logger = Logger.new(logfile || "/dev/null") end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/bg/drb_runner.rb', line 7 def logger @logger end |
Instance Method Details
#ready? ⇒ Boolean
13 14 15 |
# File 'lib/bg/drb_runner.rb', line 13 def ready? true end |
#run(proc: nil, args: []) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bg/drb_runner.rb', line 17 def run(proc: nil, args: []) Thread.new do begin sleep 0 method = "define_method :run #{proc}" runner = Class.new { eval method } logger.info "Start exec: #{method}" runner.new.run(*Marshal.load(args)) logger.info "Finish exec: #{method}" rescue Exception => e logger.error "Failed exec: #{method}\n#{e}" ensure DRb.stop_service rescue nil Process.exit end end end |