require 'scrubyt'

class FooWorker < BackgrounDRb::MetaWorker
  set_worker_name :foo_worker
  #  reload_on_schedule true
  pool_size(10)

  def create(args = nil)
    puts "started"
    cache[:start_message] = "Running"
#     @proxy_connection = nil
#     connect("localhost",11001,ProxyConnection) { |conn| @proxy_connection = conn }
  end

  def barbar(args = nil)
    logger.info "running bar bar #{Time.now} #{args}"
  end

  def who arg
    puts "running method who with #{arg}"
    google_data = Scrubyt::Extractor.define do
      fetch 'http://www.google.com/ncr'
      fill_textfield 'q', arg
      submit
      #Construct the wrapper
      link "Ruby Programming Language" do
        url "href", :type => :attribute
      end
      next_page "Next", :limit => 2
    end

    puts google_data.to_xml
  end

  def baz args
    puts "running baz with #{args}"
    return "hemant : #{args}"
  end

  def some_job count
    sleep 0.5
  end

  def stress_test args = nil
    logger.info "running stress test with #{args} #{Time.now}"
  end

  def queue_length args = nil
    return thread_pool.work_queue.length
  end

  def make_request data
    result = MiddleMan.worker(:hello_worker).make_request(:some_key,data)
    return result
  end
end