A simple Lock File class written in Ruby.
en.wikipedia.org/wiki/Lock_file#Lock_files
From Gemcutter:
gem install simple_lockfile
The project page is located at gemcutter.org/gems/simple_lockfile.
require 'lockfile' l = LockFile.new({:path => "/Users/joshnesbitt/Desktop", :filename => "test.lock"}) # => "/Users/joshnesbitt/Desktop/test.lock" l.locked? # => false l.lock! # => Integer value l.locked? # => true l.process_id # => PID l.unlock! # => Integer value l.locked? # => false
I commonly use it for checking whether an expensive task is being executed:
refresh_search_index unless @lockfile.locked?
And in the method something like this:
def refresh_search_index @lockfile.lock! # ... some heavy operation ... @lockfile.unlock! end
You can check if your .lock files are expired, by passing :expire_after argument into initializer
LockFile.new({:expire_after => "1 hour"}) LockFile.new({:expire_after => "5 hours"}) LockFile.new({:expire_after => "1 minute"}) LockFile.new({:expire_after => "100 minutes"}) LockFile.new({:expire_after => "2 hours and 10 minutes"})
You can check that with expired? method:
l1 = LockFile.new({:expire_after => "1 hour"}) l1.locked? # => false l1.lock! l1.expired? # => false # more than hour passed and somewhere else l2 = LockFile.new({:expire_after => "1 hour"}) l2.locked? # => true l2.expired? # => true
To install necessary gems, please try
$ gem install bundler
then
$ bundle
Specs are run using Watchr (github.com/mynyml/watchr) to observe the /lib and /spec directories for any changes. Once installed simply do:
watchr spec/watch.rb
You don’t have to use Watchr to run the specs, I just prefer to use it over autotest as its lightweight, quick and works. You could just run the specs normally.
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
-
Greg Fitzgerald (github.com/gregf) - Gemification of LockFile.
Copyright © 2010 Josh Nesbitt <[email protected]>. See LICENSE for details.