Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update test helper

  • Loading branch information...
commit 8d5e6f66958af58acd40e0f5688d7e670543fac5 1 parent 6bfc1da
@gnufied authored
Showing with 52 additions and 16 deletions.
  1. +52 −16 script/bdrb_test_helper.rb
View
68 script/bdrb_test_helper.rb
@@ -1,7 +1,6 @@
-require File.dirname(__FILE__) + '/test_helper'
+require File.join(File.dirname(__FILE__) + "/../config/environment")
WORKER_ROOT = RAILS_ROOT + "/lib/workers"
$LOAD_PATH.unshift(WORKER_ROOT)
-require "mocha"
class Object
def self.metaclass; class << self; self; end; end
@@ -35,28 +34,65 @@ def info(data)
end
def debug(data)
end
- def error(data)
+ end
+
+ class WorkData
+ attr_accessor :args,:block,:job_method,:persistent_job_id,:job_key
+ def initialize(args,job_key,job_method,persistent_job_id)
+ @args = args
+ @job_key = job_key
+ @job_method = job_method
+ @persistent_job_id = persistent_job_id
end
end
+
+ class ThreadPool
+ attr_accessor :size,:threads,:work_queue,:logger
+ attr_accessor :result_queue,:master
+
+ def initialize(master,size)
+ @master = master
+ @logger = logger
+ @size = size
+ @threads = []
+ end
+
+ def defer(method_name,args = nil)
+ job_key = Thread.current[:job_key]
+ persistent_job_id = Thread.current[:persistent_job_id]
+ t = WorkData.new(args,job_key,method_name,persistent_job_id)
+ result = run_task(t)
+ result
+ end
+
+ # run tasks popped out of queue
+ def run_task task
+ block_arity = master.method(task.job_method).arity
+ begin
+ t_data = task.args
+ result = nil
+ if block_arity != 0
+ result = master.send(task.job_method,task.args)
+ else
+ result = master.send(task.job_method)
+ end
+ return result
+ rescue
+ puts($!.to_s)
+ puts($!.backtrace.join("\n"))
+ return nil
+ end
+ end
+ end #end of class ThreadPool
+
class MetaWorker
- attr_accessor :logger
- attr_accessor :thread_pool
+ attr_accessor :logger,:thread_pool
iattr_accessor :worker_name
iattr_accessor :no_auto_load
def initialize
@logger = WorkerDummyLogger.new
- @thread_pool = ThreadPool.new
- end
-
- def register_status(arg)
- @status = arg
- end
- end
-
- class ThreadPool
- def defer(args,&block)
- yield args
+ @thread_pool = ThreadPool.new(self,10)
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.