Module: WorkerRoulette
- Defined in:
- lib/worker_roulette.rb,
lib/worker_roulette/lua.rb,
lib/worker_roulette/foreman.rb,
lib/worker_roulette/version.rb,
lib/worker_roulette/tradesman.rb,
lib/worker_roulette/a_tradesman.rb
Defined Under Namespace
Modules: Lua
Classes: ATradesman, Foreman, Tradesman
Constant Summary
collapse
- JOB_BOARD =
"job_board"
- JOB_NOTIFICATIONS =
"new_job_ready"
- VERSION =
"0.1.7"
Class Method Summary
collapse
Class Method Details
.a_foreman(sender, channel = nil) ⇒ Object
35
36
37
|
# File 'lib/worker_roulette.rb', line 35
def self.a_foreman(sender, channel = nil)
foreman(sender, channel)
end
|
.a_tradesman(channel = nil) ⇒ Object
39
40
41
42
|
# File 'lib/worker_roulette.rb', line 39
def self.a_tradesman(channel = nil)
raise "WorkerRoulette not Started" unless @tradesman_connection_pool
ATradesman.new(@tradesman_connection_pool, @pubsub_connection_pool, channel)
end
|
.counter_key(sender, namespace = nil) ⇒ Object
80
81
82
|
# File 'lib/worker_roulette.rb', line 80
def self.counter_key(sender, namespace = nil)
"#{namespace + ':' if namespace}counter_key"
end
|
.dump(obj) ⇒ Object
60
61
62
63
64
|
# File 'lib/worker_roulette.rb', line 60
def self.dump(obj)
Oj.dump(obj)
rescue Oj::ParseError => e
{'error' => e, 'unparsable_string' => obj}
end
|
.foreman(sender, channel = nil) ⇒ Object
25
26
27
28
|
# File 'lib/worker_roulette.rb', line 25
def self.foreman(sender, channel = nil)
raise "WorkerRoulette not Started" unless @foreman_connection_pool
Foreman.new(sender, @foreman_connection_pool, channel)
end
|
.job_board_key(namespace = nil) ⇒ Object
72
73
74
|
# File 'lib/worker_roulette.rb', line 72
def self.job_board_key(namespace = nil)
"#{namespace + ':' if namespace}#{WorkerRoulette::JOB_BOARD}"
end
|
.load(json) ⇒ Object
66
67
68
69
70
|
# File 'lib/worker_roulette.rb', line 66
def self.load(json)
Oj.load(json)
rescue Oj::ParseError => e
{'error' => e, 'unparsable_string' => obj}
end
|
.pool_size ⇒ Object
52
53
54
|
# File 'lib/worker_roulette.rb', line 52
def self.pool_size
(@pool_config ||= {})[:size]
end
|
.pubsub_connection_pool ⇒ Object
48
49
50
|
# File 'lib/worker_roulette.rb', line 48
def self.pubsub_connection_pool
@pubsub_connection_pool
end
|
.redis_config ⇒ Object
56
57
58
|
# File 'lib/worker_roulette.rb', line 56
def self.redis_config
(@redis_config ||= {}).dup
end
|
.sender_key(sender, namespace = nil) ⇒ Object
76
77
78
|
# File 'lib/worker_roulette.rb', line 76
def self.sender_key(sender, namespace = nil)
"#{namespace + ':' if namespace}#{sender}"
end
|
.start(config = {}) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/worker_roulette.rb', line 15
def self.start(config = {})
@redis_config = { host: 'localhost', port: 6379, db: 14, driver: :hiredis, timeout: 5, evented: false, pool_size: 10 }.merge(config)
@pool_config = Hash[size: @redis_config.delete(:pool_size), timeout: @redis_config.delete(:timeout)]
@evented = @redis_config.delete(:evented)
@foreman_connection_pool = ConnectionPool.new(@pool_config) {new_redis}
@tradesman_connection_pool = ConnectionPool.new(@pool_config) {new_redis}
@pubsub_connection_pool = ConnectionPool.new(@pool_config) {new_redis_pubsub}
end
|
.tradesman(channel = nil) ⇒ Object
30
31
32
33
|
# File 'lib/worker_roulette.rb', line 30
def self.tradesman(channel = nil)
raise "WorkerRoulette not Started" unless @tradesman_connection_pool
Tradesman.new(@tradesman_connection_pool, @pubsub_connection_pool, channel)
end
|
.tradesman_connection_pool ⇒ Object
44
45
46
|
# File 'lib/worker_roulette.rb', line 44
def self.tradesman_connection_pool
@tradesman_connection_pool
end
|