Class: Drydock::StreamMonitor
- Inherits:
-
Object
- Object
- Drydock::StreamMonitor
- Extended by:
- Forwardable
- Defined in:
- lib/drydock/stream_monitor.rb
Constant Summary collapse
- CONTAINER_EVENTS =
%i( attach commit copy create destroy die exec_create exec_start export kill oom pause rename resize restart start stop top unpause )
- IMAGE_EVENTS =
%i(delete import pull push tag untag)
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(event_handler) ⇒ StreamMonitor
constructor
A new instance of StreamMonitor.
Constructor Details
#initialize(event_handler) ⇒ StreamMonitor
Returns a new instance of StreamMonitor.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/drydock/stream_monitor.rb', line 36 def initialize(event_handler) @thread = Thread.new do previous_ids = {} serial_no = 0 Docker::Event.stream do |event| serial_no += 1 is_old = previous_ids.key?(event.id) event_type = self.class.event_type_for(event.status) event_handler.call(event, !is_old, serial_no, event_type) previous_ids[event.id] = true end end end |
Class Method Details
.event_type_for(type) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/drydock/stream_monitor.rb', line 25 def self.event_type_for(type) case type.to_sym when *CONTAINER_EVENTS :container when *IMAGE_EVENTS :image else :object end end |