module ProcessSyncMixin

Public Instance Methods

lock() click to toggle source

lock the temp file

# File lib/simple_rotate/internal/process_sync_mixin.rb, line 16
def lock
    reopen_temp_file

    cnt = 0
    begin
        @@tempf.flock(File::LOCK_EX)

    rescue
        cnt += 1
        if (cnt <= @try_limit)
            sleep(0.5)
            create_tempfile if !tempf_exists?
            retry
        else
          SimpleRotate::Error.warning("It was not possible to lock (tried 3times) => #{@@tempf_name}")
          return false
        end
    end
end
locked?() click to toggle source
# File lib/simple_rotate/internal/process_sync_mixin.rb, line 6
def locked?
    return false if !tempf_exists?

    # return false, if locked by another
    status = @@tempf.flock(File::LOCK_EX | File::LOCK_NB)

    return status == false
end
unlock() click to toggle source

unlock the temp file

# File lib/simple_rotate/internal/process_sync_mixin.rb, line 37
def unlock
  return nil if !tempf_exists?

  begin
      @@tempf.flock(File::LOCK_UN)
  rescue
      SimpleRotate::Error.warning("It was not possible to unlock => #{@@tempf_name}")
  end
end