Class: KubernetesDeploy::ResourceWatcher
- Inherits:
-
Object
- Object
- KubernetesDeploy::ResourceWatcher
- Defined in:
- lib/kubernetes-deploy/resource_watcher.rb
Instance Method Summary collapse
-
#initialize(resources, logger:, deploy_started_at: Time.now.utc) ⇒ ResourceWatcher
constructor
A new instance of ResourceWatcher.
- #run(delay_sync: 3.seconds, reminder_interval: 30.seconds) ⇒ Object
Constructor Details
#initialize(resources, logger:, deploy_started_at: Time.now.utc) ⇒ ResourceWatcher
Returns a new instance of ResourceWatcher.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/kubernetes-deploy/resource_watcher.rb', line 4 def initialize(resources, logger:, deploy_started_at: Time.now.utc) unless resources.is_a?(Enumerable) raise ArgumentError, <<-MSG.strip_heredoc ResourceWatcher expects Enumerable collection, got `#{resources.class}` instead MSG end @resources = resources @logger = logger @deploy_started_at = deploy_started_at end |
Instance Method Details
#run(delay_sync: 3.seconds, reminder_interval: 30.seconds) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/kubernetes-deploy/resource_watcher.rb', line 15 def run(delay_sync: 3.seconds, reminder_interval: 30.seconds) delay_sync_until = = Time.now.utc while @resources.present? if Time.now.utc < delay_sync_until sleep(delay_sync_until - Time.now.utc) end delay_sync_until = Time.now.utc + delay_sync # don't pummel the API if the sync is fast @resources.each(&:sync) newly_finished_resources, @resources = @resources.partition(&:deploy_finished?) if newly_finished_resources.present? watch_time = (Time.now.utc - @deploy_started_at).round(1) report_what_just_happened(newly_finished_resources, watch_time) report_what_is_left(reminder: false) = Time.now.utc elsif due_for_reminder?(, reminder_interval) report_what_is_left(reminder: true) = Time.now.utc end end end |