Class: PgLocksMonitor::Configuration

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

Constant Summary collapse

DEFAULT =
{
  locks_limit: 5,
  monitor_locks: true,
  monitor_blocking: true,
  locks_min_duration_ms: 200,
  blocking_min_duration_ms: 100,
  notify_logs: true,
  notify_slack: false,
  slack_webhook_url: nil,
  slack_channel: nil,
  notifier_class: PgLocksMonitor::DefaultNotifier,
  locks_filter_proc: ->(lock) { true },
  blocking_filter_proc: ->(lock) { true },
}
DEFAULT_CONFIG_FILE =
<<-CONFIG
# Configuration for pg-locks-monitor

PgLocksMonitor.configure do |config|
  config.locks_limit = #{DEFAULT[:locks_limit]}

  config.monitor_locks = #{DEFAULT[:monitor_locks]}
  config.monitor_blocking = #{DEFAULT[:monitor_blocking]}

  config.locks_min_duration_ms = #{DEFAULT[:locks_min_duration_ms]}
  config.blocking_min_duration_ms = #{DEFAULT[:blocking_min_duration_ms]}

  config.notify_logs = #{DEFAULT[:notify_logs]}

  config.notify_slack = #{DEFAULT[:notify_slack]}
  config.slack_webhook_url = "#{DEFAULT[:slack_webhook_url]}"
  config.slack_channel = "#{DEFAULT[:slack_channel]}"

  config.notifier_class = #{DEFAULT[:notifier_class]}

  config.locks_filter_proc = ->(lock) { true }
  config.blocking_filter_proc = ->(lock) { true }
end
CONFIG

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Configuration

Returns a new instance of Configuration.



22
23
24
25
26
27
# File 'lib/pg_locks_monitor/configuration.rb', line 22

def initialize(attrs)
  DEFAULT.keys.each do |key|
    value = attrs.fetch(key) { DEFAULT.fetch(key) }
    public_send("#{key}=", value)
  end
end