Class: KubernetesDeploy::ResourceWatcher
- Inherits:
-
Object
- Object
- KubernetesDeploy::ResourceWatcher
- Extended by:
- StatsD::MeasureMethods
- Defined in:
- lib/kubernetes-deploy/resource_watcher.rb
Instance Method Summary collapse
-
#initialize(resources:, task_config:, deploy_started_at: Time.now.utc, operation_name: "deploy", timeout: nil, sha: nil) ⇒ ResourceWatcher
constructor
A new instance of ResourceWatcher.
- #run(delay_sync: 3.seconds, reminder_interval: 30.seconds, record_summary: true) ⇒ Object
Methods included from StatsD::MeasureMethods
Constructor Details
#initialize(resources:, task_config:, deploy_started_at: Time.now.utc, operation_name: "deploy", timeout: nil, sha: nil) ⇒ ResourceWatcher
Returns a new instance of ResourceWatcher.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/kubernetes-deploy/resource_watcher.rb', line 11 def initialize(resources:, task_config:, deploy_started_at: Time.now.utc, operation_name: "deploy", timeout: nil, sha: nil) unless resources.is_a?(Enumerable) raise ArgumentError, <<~MSG ResourceWatcher expects Enumerable collection, got `#{resources.class}` instead MSG end @resources = resources @task_config = task_config @deploy_started_at = deploy_started_at @operation_name = operation_name @timeout = timeout @sha = sha end |
Instance Method Details
#run(delay_sync: 3.seconds, reminder_interval: 30.seconds, record_summary: true) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/kubernetes-deploy/resource_watcher.rb', line 26 def run(delay_sync: 3.seconds, reminder_interval: 30.seconds, record_summary: true) = monitoring_started = Time.now.utc remainder = @resources.dup while remainder.present? report_and_give_up(remainder) if global_timeout?(monitoring_started) sleep_until_next_sync(delay_sync) sync_resources(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 |