Module: PgLocksMonitor

Defined in:
lib/pg-locks-monitor.rb,
lib/pg_locks_monitor/version.rb,
lib/pg_locks_monitor/configuration.rb,
lib/pg_locks_monitor/default_notifier.rb

Defined Under Namespace

Classes: Configuration, DefaultNotifier, Railtie

Constant Summary collapse

VERSION =
"0.2.2"

Class Method Summary collapse

Class Method Details

.configurationObject



32
33
34
# File 'lib/pg-locks-monitor.rb', line 32

def self.configuration
  @configuration ||= Configuration.new(Configuration::DEFAULT)
end

.configure {|configuration| ... } ⇒ Object

Yields:



36
37
38
# File 'lib/pg-locks-monitor.rb', line 36

def self.configure
  yield(configuration)
end

.snapshot!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pg-locks-monitor.rb', line 8

def self.snapshot!
  locks = RubyPgExtras.locks(
    in_format: :hash,
  ).select do |lock|
    if (age = lock.fetch("age"))
      (ActiveSupport::Duration.parse(age).to_f * 1000) > configuration.locks_min_duration_ms
    end
  end.select(&configuration.locks_filter_proc)
    .first(configuration.locks_limit)

  if locks.count > 0 && configuration.monitor_locks
    configuration.notifier_class.call(locks)
  end

  blocking = RubyPgExtras.blocking(in_format: :hash).select do |block|
    (ActiveSupport::Duration.parse(block.fetch("blocking_duration")).to_f * 1000) > configuration.blocking_min_duration_ms
  end.select(&configuration.blocking_filter_proc)
    .first(configuration.locks_limit)

  if blocking.count > 0 && configuration.monitor_blocking
    configuration.notifier_class.call(blocking)
  end
end