Module: DTK::Client::Poller
- Included in:
- CommandBaseThor
- Defined in:
- lib/commands/common/thor/poller.rb
Constant Summary collapse
- PERIOD_WAIT_TIME =
1
Instance Method Summary collapse
- #poller_response(wait_time = PERIOD_WAIT_TIME) ⇒ Object
- #print_response(message_array) ⇒ Object
- #resolve_type(message_type) ⇒ Object
Instance Method Details
#poller_response(wait_time = PERIOD_WAIT_TIME) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/commands/common/thor/poller.rb', line 23 def poller_response(wait_time = PERIOD_WAIT_TIME) begin response = nil thread = Thread.new(self) do |main_thread| begin while true = main_thread.get main_thread.rest_url("messages/retrieve") print_response(.data) if .ok? sleep(wait_time) end rescue => e puts e. pp e.backtrace end end response = yield ensure thread.kill end response end |
#print_response(message_array) ⇒ Object
46 47 48 49 50 |
# File 'lib/commands/common/thor/poller.rb', line 46 def print_response() .each do |msg| DTK::Client::OsUtil.print(msg['message'], resolve_type(msg['type'])) end end |
#resolve_type(message_type) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/commands/common/thor/poller.rb', line 52 def resolve_type() case .to_sym when :info :white when :warning :yellow when :error :red else :white end end |