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(hostname, config = {}) ⇒ Client
constructor
A new instance of Client.
- #publish(watcher, message, ack = false) ⇒ Object
- #queue_prefix ⇒ Object
- #start_watchers ⇒ Object
- #stop_watchers ⇒ Object
- #trap_signals ⇒ Object
- #watchers ⇒ Object
Constructor Details
#initialize(hostname, config = {}) ⇒ Client
Returns a new instance of Client.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bender/client.rb', line 32 def initialize(hostname, config = {}) @config = config @queue_name = "#{self.queue_prefix}-#{hostname}" @config[:create_options] ||= { :visibility_timeout => 90, :maximum_message_size => 262144 } @config[:poll_options] ||= { :wait_time_seconds => 10, :idle_timeout => 5 } initialize_watchers if @config[:watchers] end |
Class Method Details
.keep_running? ⇒ Boolean
19 20 21 |
# File 'lib/bender/client.rb', line 19 def keep_running? @@keep_running end |
.sqs ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/bender/client.rb', line 23 def sqs @@sqs ||= AWS::SQS.new({ :access_key_id => ENV['AWS_ACCESS_KEY'], :secret_access_key => ENV['AWS_SECRET_ACCESS'], :region => ENV['AWS_REGION'] }) end |
Instance Method Details
#config ⇒ Object
93 94 95 |
# File 'lib/bender/client.rb', line 93 def config @config end |
#publish(watcher, message, ack = false) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bender/client.rb', line 80 def publish(watcher, , ack = false) @watchers.select{|w| w.class.to_s.underscore == watcher.to_s}.collect do |watcher| if ack with_confirmation do |cq| watcher.publish(, cq) end else watcher.publish() end Bender.logger.info("Sent message to #{watcher.name}") end end |
#queue_prefix ⇒ Object
48 49 50 |
# File 'lib/bender/client.rb', line 48 def queue_prefix @queue_prefix ||= self.config[:queue_prefix] || "#{ENV['QUEUE_PREFIX']}" end |
#start_watchers ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bender/client.rb', line 61 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
74 75 76 77 78 |
# File 'lib/bender/client.rb', line 74 def stop_watchers puts "Stopping watchers..." @@keep_running = false ThreadsWait.all_waits(*@threads) end |
#trap_signals ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/bender/client.rb', line 52 def trap_signals %w{INT TERM}.each do |signal| Signal.trap(signal) { stop_watchers exit } end end |
#watchers ⇒ Object
97 98 99 |
# File 'lib/bender/client.rb', line 97 def watchers @watchers end |