Class: KubernetesDeploy::ResourceWatcher
- Inherits:
-
Object
- Object
- KubernetesDeploy::ResourceWatcher
- Defined in:
- lib/kubernetes-deploy/resource_watcher.rb
Instance Method Summary collapse
-
#initialize(resources:, sync_mediator:, logger:, deploy_started_at: Time.now.utc, operation_name: "deploy", timeout: nil) ⇒ ResourceWatcher
constructor
A new instance of ResourceWatcher.
- #run(delay_sync: 3.seconds, reminder_interval: 30.seconds, record_summary: true) ⇒ Object
Constructor Details
#initialize(resources:, sync_mediator:, logger:, deploy_started_at: Time.now.utc, operation_name: "deploy", timeout: nil) ⇒ ResourceWatcher
Returns a new instance of ResourceWatcher.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/kubernetes-deploy/resource_watcher.rb', line 4 def initialize(resources:, sync_mediator:, logger:, deploy_started_at: Time.now.utc, operation_name: "deploy", timeout: nil) unless resources.is_a?(Enumerable) raise ArgumentError, <<~MSG ResourceWatcher expects Enumerable collection, got `#{resources.class}` instead MSG end @resources = resources @logger = logger @sync_mediator = sync_mediator @deploy_started_at = deploy_started_at @operation_name = operation_name @timeout = timeout end |
Instance Method Details
#run(delay_sync: 3.seconds, reminder_interval: 30.seconds, record_summary: true) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kubernetes-deploy/resource_watcher.rb', line 19 def run(delay_sync: 3.seconds, reminder_interval: 30.seconds, record_summary: true) delay_sync_until = = monitoring_started = Time.now.utc remainder = @resources.dup while remainder.present? if @timeout && (Time.now.utc - monitoring_started > @timeout) report_and_give_up(remainder) end if (sleep_duration = delay_sync_until - Time.now.utc) > 0 sleep(sleep_duration) end delay_sync_until = Time.now.utc + delay_sync # don't pummel the API if the sync is fast @sync_mediator.sync(remainder) new_successes, remainder = remainder.partition(&:deploy_succeeded?) new_failures, remainder = remainder.partition(&:deploy_failed?) new_timeouts, remainder = remainder.partition(&:deploy_timed_out?) if new_successes.present? || new_failures.present? || new_timeouts.present? report_what_just_happened(new_successes, new_failures, new_timeouts) report_what_is_left(remainder, reminder: false) = Time.now.utc elsif due_for_reminder?(, reminder_interval) report_what_is_left(remainder, reminder: true) = Time.now.utc end end record_statuses_for_summary(@resources) if record_summary end |