Class: Bender::Client
- Inherits:
-
Object
- Object
- Bender::Client
- Defined in:
- lib/bender/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #publish(watcher, message) ⇒ Object
- #start_watchers ⇒ Object
- #stop_watchers ⇒ Object
- #trap_signals ⇒ Object
- #watchers ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
27 28 29 30 |
# File 'lib/bender/client.rb', line 27 def initialize(config) @config = config initialize_watchers end |
Class Method Details
.keep_running? ⇒ Boolean
18 19 20 |
# File 'lib/bender/client.rb', line 18 def keep_running? @@keep_running end |
.queue_prefix ⇒ Object
22 23 24 |
# File 'lib/bender/client.rb', line 22 def queue_prefix @@queue_prefix ||= "#{ENV['QUEUE_PREFIX']}-#{Socket.gethostname}" end |
Instance Method Details
#config ⇒ Object
67 68 69 |
# File 'lib/bender/client.rb', line 67 def config @config end |
#publish(watcher, message) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/bender/client.rb', line 60 def publish(watcher, ) sent = @watchers.select{|w| w.class.to_s.underscore == watcher}.collect do |watcher| watcher.publish() end Bender.logger.info("Sent #{sent.size} message(s)") end |
#start_watchers ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bender/client.rb', line 41 def start_watchers Bender.logger.info("Starting Watchers - Press Ctrl+C to stop watchers...") @@keep_running = true @threads = [] @watchers.each do |watcher| @threads << Thread.new do watcher.start end end trap_signals ThreadsWait.all_waits(*@threads) end |
#stop_watchers ⇒ Object
54 55 56 57 58 |
# File 'lib/bender/client.rb', line 54 def stop_watchers puts "Stopping watchers..." @@keep_running = false ThreadsWait.all_waits(*@threads) end |
#trap_signals ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/bender/client.rb', line 32 def trap_signals %w{INT TERM}.each do |signal| Signal.trap(signal) { stop_watchers exit } end end |
#watchers ⇒ Object
71 72 73 |
# File 'lib/bender/client.rb', line 71 def watchers @watchers end |