Changeset 327 for trunk

Show
Ignore:
Timestamp:
08/10/08 03:34:20 (5 months ago)
Author:
gethema..@gmail.com
Message:

sync code with git

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/foo_controller.rb

    r326 r327  
    99 
    1010  def start_worker 
    11     MiddleMan.new_worker(:worker => :error_worker, :job_key => :hello_world,:data => "wow_man",:schedule => { :hello_world => { :trigger_args => "*/5 * * * * * *",:data => "hello_world" }}
     11    MiddleMan.new_worker(:worker => :error_worker, :worker_key => :hello_world,:data => "wow_man"
    1212    render :text => "worker starterd" 
    1313  end 
    1414 
    1515  def stop_worker 
    16     MiddleMan.delete_worker(:worker => :error_worker, :job_key => :hello_world) 
     16    MiddleMan.worker(:error_worker,:hello_world).delete 
    1717    render :text => "worker deleted" 
    1818  end 
    1919 
    2020  def invoke_worker_method 
    21     worker_response = MiddleMan.send_request(:worker => :world_worker, :worker_method => :hello_world
     21    worker_response = MiddleMan.worker(:hello_worker).say_hello(:arg => data
    2222    render :text => worker_response 
    2323  end 
    2424 
    2525  def renew 
    26     MiddleMan.ask_work(:worker => :renewal_worker, :worker_method => :load_policies
     26    MiddleMan.worker(:hello_worker).async_load_policy(:arg => current_user.id
    2727    render :text => "method invoked" 
    2828  end 
    2929 
    30   def ask_statu
     30  def query_all_worker
    3131    t_response = MiddleMan.query_all_workers 
    3232    running_workers = t_response.map { |key,value| "#{key} = #{value}"}.join(',') 
    3333    render :text => running_workers 
     34  end 
     35 
     36  def ask_result 
     37    t_result = MiddleMan.worker(:hello_worker).ask_result(cache_key) 
    3438  end 
    3539 
  • trunk/examples/workers/foo_worker.rb

    r326 r327  
    2424 
    2525  def get_external_data(p_data) 
    26     register_status(p_data) 
     26    cache[some_key] = p_data 
    2727  end 
    2828 
    2929  def foobar 
    30     register_status("Hello #{Time.now}") 
     30    cache[some_key] = "Time is now : #{Time.now}" 
    3131  end 
    3232 
  • trunk/examples/workers/rss_worker.rb

    r326 r327  
    1010  def fetch_url(url) 
    1111    puts "fetching url #{url}" 
    12     thread_pool.defer(url) do |url| 
    13       begin 
    14         data = Net::HTTP.get('www.example.com','/') 
    15         File.open("#{RAILS_ROOT}/log/pages.txt","w") do |fl| 
    16           fl.puts(data) 
    17         end 
    18       rescue 
    19         logger.info "Error downloading page" 
     12    thread_pool.defer(:scrap_things,url) 
     13  end 
     14 
     15  def scrap_things url 
     16    begin 
     17      data = Net::HTTP.get(url,"/") 
     18      File.open("#{RAILS_ROOT}/log/pages.txt","w") do |fl| 
     19        fl.puts(data) 
    2020      end 
     21    rescue 
     22      logger.info "Error downloading page" 
    2123    end 
    2224  end 
  • trunk/lib/backgroundrb/bdrb_cluster_connection.rb

    r326 r327  
    137137      end 
    138138      raise NoServerAvailable.new("No BackgrounDRb server is found running") unless succeeded 
     139      return options[:worker_key] 
    139140    end 
    140141 
  • trunk/lib/backgroundrb/bdrb_connection.rb

    r326 r327  
    149149        @mutex.synchronize { bdrb_response = read_from_bdrb() } 
    150150        close_connection 
    151         return bdrb_response[:data] 
     151        bdrb_response ? bdrb_response[:data] : nil 
    152152      end 
    153153    end 
  • trunk/script/load_worker_env.rb

    r326 r327  
    2020if !(::Packet::WorkerRunner::WORKER_OPTIONS[:worker_env] == false) 
    2121  require RAILS_HOME + "/config/environment" 
     22  ActiveRecord::Base.allow_concurrency = true 
    2223end 
    2324require "backgroundrb_server" 
  • trunk/server/lib/meta_worker.rb

    r326 r327  
    2323  end 
    2424  # == MetaWorker class 
    25   # BackgrounDRb workers are asynchrounous reactors which work using events 
     25  # BackgrounDRb workers are asynchronous reactors which work using events 
    2626  # You are free to use threads in your workers, but be reasonable with them. 
    2727  # Following methods are available to all workers from parent classes. 
     
    214214    end 
    215215 
    216     # can the respones be dumped? 
     216    # can the responses be dumped? 
    217217    def can_dump?(p_object) 
    218218      begin 
  • trunk/test/bdrb_client_test_helper.rb

    r326 r327  
    33require "bdrb_client_helper" 
    44require "bdrb_cluster_connection" 
     5require "bdrb_conn_error" 
  • trunk/test/client/test_bdrb_cluster_connection.rb

    r326 r327  
    55  class BackgrounDRb::Connection 
    66    attr_accessor :server_ip,:server_port,:cluster_conn,:connection_status 
    7     def initialize ip,port,cluster_connection 
    8       @server_ip = ip 
    9       @server_port = port 
    10     end 
    117    def establish_connection 
    128      @connection_status = true 
    139    end 
     10 
    1411    def close_connection 
    1512      @connection_status = false 
     
    9289      t_conn.expects(:new_worker).with(:worker => :hello_worker,:worker_key => "boy",:data => "boy").returns(true) 
    9390    end 
    94     @cluster_connection.new_worker(:worker => :hello_worker,:worker_key => "boy",:data => "boy") 
     91    a = @cluster_connection.new_worker(:worker => :hello_worker,:worker_key => "boy",:data => "boy") 
     92    a.should == "boy" 
    9593  end 
    9694 
     
    107105  class BackgrounDRb::Connection 
    108106    attr_accessor :server_ip,:server_port,:cluster_conn,:connection_status 
    109     def initialize ip,port,cluster_connection 
    110       @server_ip = ip 
    111       @server_port = port 
    112     end 
    113107  end 
    114108 
  • trunk/test/client/test_bdrb_connection.rb

    r326 r327  
    44 
    55context "For Actual BackgrounDRB connection" do 
    6   specify "in case of timeout connection status should be false" do 
     6  setup do 
     7    options = {:schedules => { 
     8        :foo_worker => { :barbar=>{:trigger_args=>"*/5 * * * * * *"}}}, 
     9      :backgroundrb=>{:port=>11008, :ip=>"0.0.0.0", :environment=> "production"}, 
     10      :client => "localhost:11001,localhost:11002,localhost:11003" 
     11    } 
     12    BDRB_CONFIG.set(options) 
    713    @cluster = mock() 
    8     @connection = BackgrounDRb::Connection.new('localhost',1267,@cluster) 
    9     @connection.establish_connection 
     14    @foo_connection = BackgrounDRb::Connection.new('localhost',1267,"crap") 
     15    @foo_connection.stubs(:close_connection) 
     16    class << @foo_connection 
     17      attr_accessor :outgoing_data 
     18      def dump_object data 
     19        @outgoing_data = data 
     20      end 
     21    end 
     22  end 
     23 
     24  specify "should return nil if ask_result returns nil" do 
     25    a = @foo_connection.ask_result(:worker => 'foo_worker',:worker_key => 'bar',:job_key => 10) 
     26    a.should == nil 
     27    @foo_connection.outgoing_data.should == {:type=>:get_result, :job_key=>10, :worker=>"foo_worker", :worker_key=>"bar"} 
    1028  end 
    1129end