I am having concurrency issues between two processes after short research I have seen that temporary file
is suggested solution to this problem.
So solution would be to create /tmp/global.lock
and use it as global lock. Example of this I have found in this thread Mutex for Rails Processes
Make sense to me so far, but I would like to see best practice for this solution. Above explained make sense but I wonder how to check if given file is locked?
fh = File.open("/some/file/path", File::CREAT)
begin
if locked = check_file_locked?
sleep(1)
else
fh.flock(File::LOCK_EX)
# do what you need to do
end
ensure
fh.flock(File::LOCK_UN)
end
This is my understanding of solution and not sure how to implement mentioned check_file_locked?()
? Also if there is best way would love to hear it.