Sha256: 4c46aeb2a28682a91027564df48c78f0dfb0358d33052bff8c37340007c8c7f3
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
module ProcessSyncMixin @@scheduled_del_lockfile = false @@tempf_name = nil @@tempf = nil 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 # lock the temp file def lock create_tempfile if !tempf_exists? 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 # unlock the temp file 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 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
simple_rotate-1.1.1 | lib/simple_rotate/internal/process_sync_mixin.rb |
simple_rotate-1.1.0 | lib/simple_rotate/internal/process_sync_mixin.rb |