Module: Webhookdb::Async::Autoscaler
- Includes:
- Appydays::Configurable, Appydays::Loggable
- Defined in:
- lib/webhookdb/async/autoscaler.rb
Defined Under Namespace
Classes: FakeImplementation
Constant Summary collapse
- AVAILABLE_PROVIDERS =
["heroku", "fake"].freeze
Class Method Summary collapse
- ._check_provider! ⇒ Object
- .build_implementation ⇒ Object
- .enabled? ⇒ Boolean
- .scale_down(depth:, duration:) ⇒ Object
- .scale_up(names_and_latencies, depth:, duration:) ⇒ Object
- .start ⇒ Object
- .stop ⇒ Object
Class Method Details
._check_provider! ⇒ Object
14 15 16 17 18 |
# File 'lib/webhookdb/async/autoscaler.rb', line 14 def self._check_provider! return if AVAILABLE_PROVIDERS.include?(self.provider) return if !self.enabled && self.provider.blank? raise "invalid AUTOSCALER_PROVIDER: '#{self.provider}', one of: #{AVAILABLE_PROVIDERS.join(', ')}" end |
.build_implementation ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/webhookdb/async/autoscaler.rb', line 40 def build_implementation case self.provider when "heroku" opts = {heroku: Webhookdb::Heroku.client, max_additional_workers: self.max_additional_workers} (opts[:app_id_or_app_name] = self.heroku_app_id_or_app_name) if self.heroku_app_id_or_app_name.present? (opts[:formation_id_or_formation_type] = self.heroku_formation_id_or_formation_type) if self.heroku_formation_id_or_formation_type.present? return Amigo::Autoscaler::Heroku.new(**opts) when "fake" return FakeImplementation.new else self._check_provider! end end |
.enabled? ⇒ Boolean
38 |
# File 'lib/webhookdb/async/autoscaler.rb', line 38 def enabled? = self.enabled |
.scale_down(depth:, duration:) ⇒ Object
87 88 89 90 |
# File 'lib/webhookdb/async/autoscaler.rb', line 87 def scale_down(depth:, duration:, **) scale_action = @impl.scale_down(depth:, duration:, **) self.logger.warn("high_latency_queues_resolved", depth:, duration:, scale_action:) end |
.scale_up(names_and_latencies, depth:, duration:) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/webhookdb/async/autoscaler.rb', line 77 def scale_up(names_and_latencies, depth:, duration:, **) scale_action = @impl.scale_up(names_and_latencies, depth:, duration:, **) kw = {queues: names_and_latencies, depth:, duration:, scale_action:} self.logger.warn("high_latency_queues_event", **kw) Sentry.with_scope do |scope| scope&.set_extras(**kw) Sentry.("Some queues have a high latency") end end |
.start ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/webhookdb/async/autoscaler.rb', line 56 def start raise "already started" unless @instance.nil? @impl = self.build_implementation @instance = Amigo::Autoscaler.new( poll_interval: self.poll_interval, latency_threshold: self.latency_threshold, hostname_regex: self.hostname_regex, handlers: [self.method(:scale_up)], alert_interval: self.alert_interval, latency_restored_threshold: self.latency_restored_threshold, latency_restored_handlers: [self.method(:scale_down)], log: ->(level, msg, kw={}) { self.logger.send(level, msg, kw) }, ) return @instance.start end |
.stop ⇒ Object
72 73 74 75 |
# File 'lib/webhookdb/async/autoscaler.rb', line 72 def stop raise "not started" if @instance.nil? @instance.stop end |