Changeset 270

Show
Ignore:
Timestamp:
12/13/07 07:39:41 (8 months ago)
Author:
gethema..@gmail.com
Message:

new code for backgroundrb with exceptions and fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/backgroundrb.rb

    r252 r270  
    55require File.dirname(__FILE__) + "/../framework/bin_parser" 
    66require File.dirname(__FILE__) + "/../framework/nbio" 
     7require "bdrb_conn_error" 
    78 
    89module BackgrounDRb 
     
    2728      @connection_status = true 
    2829    rescue Timeout::Error 
    29       puts $! 
    30       puts $!.backtrace 
    3130      @connection_status = false 
    3231    rescue Exception => e 
    33       puts $! 
    34       puts $!.backtrace 
    3532      @connection_status = false 
    3633    end 
     
    4037    p_data[:type] = :do_work 
    4138    establish_connection() 
    42     raise "Error connecting to master process" unless @connection_status 
     39    p @connection_status 
     40    raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status 
    4341    dump_object(p_data,@connection) 
    4442    # @connection.close 
     
    4846    p_data[:type] = :start_worker 
    4947    establish_connection 
    50     raise "Error connecting to master process" unless @connection_status 
     48    raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status 
    5149    dump_object(p_data,@connection) 
    5250    # @connection.close 
     
    5654    p_data[:type] = :delete_worker 
    5755    establish_connection 
    58     raise "Error connecting to master process" unless @connection_status 
     56    raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status 
    5957    dump_object(p_data,@connection) 
    6058    # @connection.close 
     
    7674      @tokenizer.extract(sock_data) { |b_data| return b_data } 
    7775    rescue 
    78       raise "Error reading from master" 
     76      raise BackgrounDRb::BdrbConnError.new("Not able to connect") 
    7977    end 
    8078  end 
     
    8482    p_data[:type] = :all_worker_status 
    8583    establish_connection 
    86     raise "Err connecting to master process" unless @connection_status 
     84    raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status 
    8785    dump_object(p_data,@connection) 
    8886    begin 
     
    108106    establish_connection() 
    109107 
    110     raise "Err connecting to master process" unless @connection_status 
     108    raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status 
    111109    dump_object(p_data,@connection) 
    112110    begin 
     
    132130    establish_connection() 
    133131 
    134     raise "Err connecting to master process" unless @connection_status 
     132    raise BackgrounDRb::BdrbConnError.new("Not able to connect") unless @connection_status 
    135133    dump_object(p_data,@connection) 
    136134    begin 
  • trunk/server/meta_worker.rb

    r269 r270  
    168168    end 
    169169 
    170     # we are overriding the function that checks for timers 
    171 #     def check_for_timer_events 
    172 #       super 
    173 #       return unless @my_schedule 
    174 #       if @run_time < Time.now.to_i 
    175 #         # self.send(@my_schedule[:worker_method]) if self.respond_to?(@my_schedule[:worker_method]) 
    176 #         invoke_worker_method 
    177 #         @run_time = @trigger.fire_time_after(Time.now).to_i 
    178 #       end 
    179 #     end 
     170    #     we are overriding the function that checks for timers 
     171    #     def check_for_timer_events 
     172    #       super 
     173    #       return unless @my_schedule 
     174    #       if @run_time < Time.now.to_i 
     175    #         # self.send(@my_schedule[:worker_method]) if self.respond_to?(@my_schedule[:worker_method]) 
     176    #         invoke_worker_method 
     177    #         @run_time = @trigger.fire_time_after(Time.now).to_i 
     178    #       end 
     179    #     end 
    180180 
    181181    def invoke_worker_method 
  • trunk/test/backgroundrb_test.rb

    r217 r270  
    1 require 'test/unit' 
     1require File.join(File.dirname(__FILE__) + "/bdrb_test_helper") 
     2require "backgroundrb" 
    23 
    3 class BackgroundrbTest < Test::Unit::TestCase 
    4   # Replace this with your real tests. 
    5   def test_this_plugin 
    6     flunk 
     4context "Backgroundrb connection in general should" do 
     5  specify "ask_work should throw exception if connection cant be established" do 
     6    should.raise(BackgrounDRb::BdrbConnError) do 
     7      MiddleMan.ask_work(:worker => :hello_worker, :worker_method => :say_hello) 
     8    end 
    79  end 
    810end 
     11 
     12