14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/inat-channel/lock.rb', line 14
def acquire!
file = IC::CONFIG.dig(:lock_file, :path)
FileUtils.mkdir_p File.dirname(file)
if File.exist?(file)
data = load_data file
if stale?(data)
IC::logger.info "Remove stale lock: #{file}"
File.delete file
else
raise "Another instance is already running (PID: #{data[:pid]})"
end
end
data = {
pid: Process.pid,
started_at: Time.now.utc.iso8601
}
File.write file, JSON.pretty_generate(data)
IC::logger.info "Lock acquired: #{file}"
end
|