class Rufus::Scheduler

def lock


easy.
overriding implementation for this #lock and the #unlock complement is
If one needs to use a special/different locking mechanism, providing

so it probably won't work reliably on distributed file systems.
run (to first to write the lockfile and lock it). It uses "man 2 flock"
it easy for schedulers on the same machine to determine which should
:lockfile => 'path/to/lock/file' scheduler start option. It makes
Out of the box, rufus-scheduler proposes the

not run, the method should return false.
only one of them should run the scheduler. For schedulers that should
return true. It is useful in cases where among a group of applications
Most of the time, a scheduler is run alone and this method should

thus may run.
Returns true if the scheduler has acquired the [exclusive] lock and
def lock
  @lockfile = nil
  return true unless f = @opts[:lockfile]
  raise ArgumentError.new(
    ":lockfile argument must be a string, not a #{f.class}"
  ) unless f.is_a?(String)
  FileUtils.mkdir_p(File.dirname(f))
  f = File.new(f, File::RDWR | File::CREAT)
  locked = f.flock(File::LOCK_NB | File::LOCK_EX)
  return false unless locked
  now = Time.now
  f.print("pid: #{$$}, ")
  f.print("scheduler.object_id: #{self.object_id}, ")
  f.print("time: #{now}, ")
  f.print("timestamp: #{now.to_f}")
  f.flush
  @lockfile = f
  true
end