Class: WorkerRoulette::WorkerRoulette
- Inherits:
-
Object
- Object
- WorkerRoulette::WorkerRoulette
- Defined in:
- lib/worker_roulette.rb
Constant Summary collapse
- JOB_BOARD =
"job_board"
- JOB_NOTIFICATIONS =
"new_job_ready"
- DEFAULT_POLLING_TIME =
2
Class Method Summary collapse
- .counter_key(sender, namespace = nil) ⇒ Object
- .dump(obj) ⇒ Object
- .job_board_key(namespace = nil) ⇒ Object
- .load(json) ⇒ Object
- .sender_key(sender, namespace = nil) ⇒ Object
- .start(config = {}) ⇒ Object
Instance Method Summary collapse
- #foreman(sender, namespace = nil) ⇒ Object
-
#initialize(config = {}) ⇒ WorkerRoulette
constructor
A new instance of WorkerRoulette.
- #polling_time ⇒ Object
- #pool_size ⇒ Object
- #redis_config ⇒ Object
- #tradesman(namespace = nil, polling_time = DEFAULT_POLLING_TIME) ⇒ Object
- #tradesman_connection_pool ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ WorkerRoulette
Returns a new instance of WorkerRoulette.
48 49 50 51 52 53 54 55 56 |
# File 'lib/worker_roulette.rb', line 48 def initialize(config = {}) @redis_config = { host: 'localhost', port: 6379, db: 14, driver: :hiredis, timeout: 5, evented: false, pool_size: 10 , polling_time: DEFAULT_POLLING_TIME}.merge(config) @pool_config = Hash[size: @redis_config.delete(:pool_size), timeout: @redis_config.delete(:timeout)] @evented = @redis_config.delete(:evented) @polling_time = @redis_config.delete(:polling_time) @foreman_connection_pool = ConnectionPool.new(@pool_config) {new_redis} @tradesman_connection_pool = ConnectionPool.new(@pool_config) {new_redis} end |
Class Method Details
.counter_key(sender, namespace = nil) ⇒ Object
37 38 39 |
# File 'lib/worker_roulette.rb', line 37 def self.counter_key(sender, namespace = nil) "#{namespace + ':' if namespace}counter_key" end |
.dump(obj) ⇒ Object
17 18 19 20 21 |
# File 'lib/worker_roulette.rb', line 17 def self.dump(obj) Oj.dump(obj) rescue Oj::ParseError => e {'error' => e, 'unparsable_string' => obj} end |
.job_board_key(namespace = nil) ⇒ Object
29 30 31 |
# File 'lib/worker_roulette.rb', line 29 def self.job_board_key(namespace = nil) "#{namespace + ':' if namespace}#{WorkerRoulette::JOB_BOARD}" end |
.load(json) ⇒ Object
23 24 25 26 27 |
# File 'lib/worker_roulette.rb', line 23 def self.load(json) Oj.load(json) rescue Oj::ParseError => e {'error' => e, 'unparsable_string' => obj} end |
.sender_key(sender, namespace = nil) ⇒ Object
33 34 35 |
# File 'lib/worker_roulette.rb', line 33 def self.sender_key(sender, namespace = nil) "#{namespace + ':' if namespace}#{sender}" end |
.start(config = {}) ⇒ Object
41 42 43 44 |
# File 'lib/worker_roulette.rb', line 41 def self.start(config = {}) instance = new(config) instance end |
Instance Method Details
#foreman(sender, namespace = nil) ⇒ Object
58 59 60 61 |
# File 'lib/worker_roulette.rb', line 58 def foreman(sender, namespace = nil) raise "WorkerRoulette not Started" unless @foreman_connection_pool Foreman.new(@foreman_connection_pool, sender, namespace) end |
#polling_time ⇒ Object
80 81 82 |
# File 'lib/worker_roulette.rb', line 80 def polling_time @polling_time end |
#pool_size ⇒ Object
72 73 74 |
# File 'lib/worker_roulette.rb', line 72 def pool_size (@pool_config ||= {})[:size] end |
#redis_config ⇒ Object
76 77 78 |
# File 'lib/worker_roulette.rb', line 76 def redis_config (@redis_config ||= {}).dup end |
#tradesman(namespace = nil, polling_time = DEFAULT_POLLING_TIME) ⇒ Object
63 64 65 66 |
# File 'lib/worker_roulette.rb', line 63 def tradesman(namespace = nil, polling_time = DEFAULT_POLLING_TIME) raise "WorkerRoulette not Started" unless @tradesman_connection_pool Tradesman.new(@tradesman_connection_pool, @evented, namespace, polling_time || @polling_time) end |
#tradesman_connection_pool ⇒ Object
68 69 70 |
# File 'lib/worker_roulette.rb', line 68 def tradesman_connection_pool @tradesman_connection_pool end |