Last active
September 28, 2015 11:18
-
-
Save samg/1430991 to your computer and use it in GitHub Desktop.
Implement a lockfile in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
begin | |
path_to_lock_file = '/tmp/lock.lock' | |
File.new(path_to_lock_file, File::CREAT|File::EXCL) # raise if file already exits | |
begin | |
system *ARGV | |
ensure | |
FileUtils.rm path_to_lock_file | |
end | |
rescue Errno::EEXIST | |
warn "Job currently running, exiting." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment