Class: SolidQueueGuard::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_queue_guard/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/solid_queue_guard/configuration.rb', line 21

def initialize
  @enabled = true
  @queue_lag_thresholds = { default: 5.minutes }
  @failed_jobs_threshold = 20
  @stale_process_threshold = 5.minutes
  @health_token = nil
  @strict_mode = false
  @health_cache_ttl = 15.seconds
  @scheduled_backlog_threshold = 100
  @integrate_rails_health = false
  @notify_with = [:rails_logger]
  @metrics_backends = []
  @disabled_checks = []
  @checks = ActiveSupport::OrderedOptions.new
  @degraded_http_status = :ok
  @unhealthy_http_status = :service_unavailable
end

Instance Attribute Details

#checksObject

Returns the value of attribute checks.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def checks
  @checks
end

#degraded_http_statusObject

Returns the value of attribute degraded_http_status.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def degraded_http_status
  @degraded_http_status
end

#disabled_checksObject

Returns the value of attribute disabled_checks.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def disabled_checks
  @disabled_checks
end

#enabledObject

Returns the value of attribute enabled.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def enabled
  @enabled
end

#failed_jobs_thresholdObject

Returns the value of attribute failed_jobs_threshold.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def failed_jobs_threshold
  @failed_jobs_threshold
end

#health_cache_ttlObject

Returns the value of attribute health_cache_ttl.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def health_cache_ttl
  @health_cache_ttl
end

#health_tokenObject

Returns the value of attribute health_token.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def health_token
  @health_token
end

#integrate_rails_healthObject

Returns the value of attribute integrate_rails_health.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def integrate_rails_health
  @integrate_rails_health
end

#metrics_backendsObject

Returns the value of attribute metrics_backends.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def metrics_backends
  @metrics_backends
end

#notify_withObject

Returns the value of attribute notify_with.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def notify_with
  @notify_with
end

#queue_lag_thresholdsObject

Returns the value of attribute queue_lag_thresholds.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def queue_lag_thresholds
  @queue_lag_thresholds
end

#scheduled_backlog_thresholdObject

Returns the value of attribute scheduled_backlog_threshold.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def scheduled_backlog_threshold
  @scheduled_backlog_threshold
end

#stale_process_thresholdObject

Returns the value of attribute stale_process_threshold.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def stale_process_threshold
  @stale_process_threshold
end

#strict_modeObject

Returns the value of attribute strict_mode.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def strict_mode
  @strict_mode
end

#unhealthy_http_statusObject

Returns the value of attribute unhealthy_http_status.



5
6
7
# File 'lib/solid_queue_guard/configuration.rb', line 5

def unhealthy_http_status
  @unhealthy_http_status
end

Instance Method Details

#check_enabled?(check_id) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/solid_queue_guard/configuration.rb', line 43

def check_enabled?(check_id)
  id = check_id.to_sym
  return false if disabled_checks.map(&:to_sym).include?(id)

  settings = check_settings_for(id)
  return true if settings.nil?

  enabled_value = settings[:enabled]
  enabled_value = settings['enabled'] if enabled_value.nil?
  enabled_value != false
end

#check_setting(check_id, key, default = nil) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/solid_queue_guard/configuration.rb', line 59

def check_setting(check_id, key, default = nil)
  settings = check_settings_for(check_id)
  return default unless settings

  value = settings[key]
  value = settings[key.to_sym] if value.nil?
  value.nil? ? default : value
end

#check_settings_for(check_id) ⇒ Object



55
56
57
# File 'lib/solid_queue_guard/configuration.rb', line 55

def check_settings_for(check_id)
  checks[check_id.to_sym] || checks[check_id.to_s]
end

#strict?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/solid_queue_guard/configuration.rb', line 39

def strict?
  strict_mode || ActiveModel::Type::Boolean.new.cast(ENV.fetch('SOLID_QUEUE_GUARD_STRICT', nil))
end