Class: Anomonitor::PollLock

Inherits:
Object
  • Object
show all
Defined in:
lib/anomonitor/poll_lock.rb

Constant Summary collapse

LOCK_KEY =

stable advisory lock id for Anomonitor

8_604_071_000
LOCK_FILE =
"tmp/anomonitor_poll.lock"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.with_lock(enabled: Anomonitor.config.poll_lock) ⇒ Object



8
9
10
11
12
# File 'lib/anomonitor/poll_lock.rb', line 8

def self.with_lock(enabled: Anomonitor.config.poll_lock)
  return yield unless enabled

  new.with_lock { yield }
end

Instance Method Details

#with_lockObject



14
15
16
17
18
19
20
# File 'lib/anomonitor/poll_lock.rb', line 14

def with_lock
  if postgres?
    with_pg_lock { yield }
  else
    with_file_lock { yield }
  end
end