|
Revision 326, 1.2 kB
(checked in by gethema..@gmail.com, 1 month ago)
|
check in new backgroundrb code
|
| Line | |
|---|
| 1 |
require File.dirname(__FILE__) + '/test_helper' |
|---|
| 2 |
WORKER_ROOT = RAILS_ROOT + "/lib/workers" |
|---|
| 3 |
$LOAD_PATH.unshift(WORKER_ROOT) |
|---|
| 4 |
require "mocha" |
|---|
| 5 |
|
|---|
| 6 |
class Object |
|---|
| 7 |
def self.metaclass; class << self; self; end; end |
|---|
| 8 |
|
|---|
| 9 |
def self.iattr_accessor *args |
|---|
| 10 |
metaclass.instance_eval do |
|---|
| 11 |
attr_accessor *args |
|---|
| 12 |
args.each do |attr| |
|---|
| 13 |
define_method("set_#{attr}") do |b_value| |
|---|
| 14 |
self.send("#{attr}=",b_value) |
|---|
| 15 |
end |
|---|
| 16 |
end |
|---|
| 17 |
end |
|---|
| 18 |
|
|---|
| 19 |
args.each do |attr| |
|---|
| 20 |
class_eval do |
|---|
| 21 |
define_method(attr) do |
|---|
| 22 |
self.class.send(attr) |
|---|
| 23 |
end |
|---|
| 24 |
define_method("#{attr}=") do |b_value| |
|---|
| 25 |
self.class.send("#{attr}=",b_value) |
|---|
| 26 |
end |
|---|
| 27 |
end |
|---|
| 28 |
end |
|---|
| 29 |
end |
|---|
| 30 |
end |
|---|
| 31 |
|
|---|
| 32 |
module BackgrounDRb |
|---|
| 33 |
class WorkerDummyLogger |
|---|
| 34 |
def info(data) |
|---|
| 35 |
end |
|---|
| 36 |
def debug(data) |
|---|
| 37 |
end |
|---|
| 38 |
def error(data) |
|---|
| 39 |
end |
|---|
| 40 |
end |
|---|
| 41 |
class MetaWorker |
|---|
| 42 |
attr_accessor :logger |
|---|
| 43 |
attr_accessor :thread_pool |
|---|
| 44 |
iattr_accessor :worker_name |
|---|
| 45 |
iattr_accessor :no_auto_load |
|---|
| 46 |
|
|---|
| 47 |
def initialize |
|---|
| 48 |
@logger = WorkerDummyLogger.new |
|---|
| 49 |
@thread_pool = ThreadPool.new |
|---|
| 50 |
end |
|---|
| 51 |
|
|---|
| 52 |
def register_status(arg) |
|---|
| 53 |
@status = arg |
|---|
| 54 |
end |
|---|
| 55 |
end |
|---|
| 56 |
|
|---|
| 57 |
class ThreadPool |
|---|
| 58 |
def defer(args,&block) |
|---|
| 59 |
yield args |
|---|
| 60 |
end |
|---|
| 61 |
end |
|---|
| 62 |
end |
|---|
| 63 |
|
|---|