views:

20

answers:

0

The following code works fine as long as I don't try to run it through the distributed server. It doesn't get there... It runs fine out of delayed_job, runs fine if called directly.
But if 'distrib' is true (the default) it runs right up to the call to the server and right past it without getting to the server or raising any errors.

Am using Ruby 1.8.6.26 , Ringy-Dingy 1.2.1, dj 1.8.4.

===The server:

require 'rinda/ring'
class ScriptServer  
  include DRbUndumped   
  attr_accessor :result  
  def run(fullScript)  
    myTS  = Time.now.strftime("%Y%m%d%H%M%S")  
    msg = "===> Starting #{scriptname} in run #{scriptrun} on #{scriptenv} at #{myTS}"  
    puts msg     
    @result = "***#{scriptname} Launched [#{scriptlaunch}]"  
    rslt = fullScript.run  
    @result << rslt  
    msg = "#{scriptname} Completed [#{Time.now.strftime("%Y%m%d%H%M%S")}]"  
    @result << "***#{msg}"  
  rescue  
    @result << "#{scriptname} Aborted [#{Time.now.strftime("%Y%m%d%H%M%S")}] \n #{$!} \n #{caller.to_yaml}"  
  ensure  
    return @result  
  end  
end  
DRb.start_service  
myPid = Process.pid.to_s  
puts myPid  
ring_server = Rinda::RingFinger.primary  
ring_server.write([:name, :ScriptServer, ScriptServer.new(), "ScriptServer #{myPid}"], Rinda::SimpleRenewer.new)  
DRb.thread.join  

===The worker/client

require 'active_support'  
require 'drb'  

class ScriptWorker      
  attr_accessor :script_id  
  attr_accessor :run_id  
  attr_accessor :distrib  

  def initialize( script_id, run_id, distrib = true )  
    self.script_id = script_id  
    self.run_id    = run_id  
    self.distrib   = distrib  
    @myLog = ''  
  end  

  def perform  
    myScript = Script.find(script_id)  
(left out setting of variables used below...)          
    require "#{myRoot}/script/#{myScript.name}"  

    fullScript = Object.const_get(myClass).new( myScript, myRun, runenv, myURI, myRoot )    

   if self.distrib      
      require 'rinda/ring'  
      DRb.start_service  
      ring_server = Rinda::RingFinger.primary  
      service = ring_server.take([:name, :ScriptServer, nil, nil])  
      server = service[2]  
      result = server.run(fullScript)  
      puts result  
   else  
      result = fullScript.run   
      puts result  
   end   
    @myLog.close  
  end  

  def init_my_log( name )  
...  
  end  
end  

===The parent script class

require 'rubygems'  
require 'util1'  
require 'drb'  

class ScriptMain   
  include Util1  
  include DRbUndumped  

  def initialize( aScript, aRun, runenv, myURI, myRoot )  
    @myScript = aScript  
    @myId = @myScript.id  
    @myName  = File.basename(@myScript.name, "*.rb")  
    @usecase = @myName  
    @myRun = aRun    
    @myRoot = myRoot  
    @rootDir = "#{RAILS_ROOT}"  
    @launch = aRun.launched  
    @runenv = runenv  
    @myURI  = myURI  
    @runid = aRun.id  
    @optionStrg = aRun.options  
    @myBrowser = ''  
    @myHwnd = 0      
  end  
end  

=== a sample child script class (Just the run method. bunch of other methods in full script)

class SearchTest < ScriptMain  

  def run( limit = 5.minutes )  
    begin  
      puts '&*&*&* I am here *&*&*&'  
      @runenv = 'WEB'  
      open_log(@myName, @rootDir, @myRoot, @launch, @start,   
               @myId, @runenv, @usecase, @runid, @optionStrg )  

      @myBrowser = Watir::IE.new_process  
      @myHwnd    = @myBrowser.hwnd  
      lookup('Google')      
      emaillogin(@myBrowser, @service, @username, @password)  
      logout(@myBrowser)  

    rescue  
      log_message(FATAL, "(#{__LINE__})  #{$!}", @@fail)  
      raise  
    ensure  
      create_flag_file(Time.new.to_f.to_s, 'parse' ) unless @runid == '99999'  
      close_log(@myName, __LINE__)  
    end        
  end #def   
end