- File.open(@config["state_file"], "r") do |fl|
- fl.flock(File::LOCK_EX)
+ File.open(@config["lock_file"], File::RDWR | File::CREAT, 0o600) do |fl|
+ # take the lock in non-blocking mode. if this process doesn't get the lock
+ # then another will be run from cron shortly. this prevents a whole bunch
+ # of processes queueing on the lock and causing weirdness if/when they
+ # get woken up in a random order.
+ got_lock = fl.flock(File::LOCK_EX | File::LOCK_NB)
+ break unless got_lock