Top Level Namespace

Defined Under Namespace

Modules: Lab Classes: Auto12Epl, CouchBum, Float, LoggerMultiplexor

Instance Method Summary collapse

Instance Method Details

#with_lock(lock_file) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/lab/install/templates/start_worker.rb', line 9

def with_lock(lock_file)
  File.open("log/#{lock_file}", File::RDWR | File::CREAT, 0o644) do |file|
    unless file.flock(File::LOCK_EX | File::LOCK_NB)
      Rails.logger.warn("Failed to start new process due to lock: #{lock_file}")
      exit 2
    end

    file.rewind
    file.puts("Process ##{Process.pid} started at #{Time.now}")

    yield
  end
end