Skip to content

joshnesbitt/lockfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LockFile

A simple Lock File class written in Ruby.

en.wikipedia.org/wiki/Lock_file#Lock_files

Installation

From Gemcutter:

gem install simple_lockfile

The project page is located at gemcutter.org/gems/simple_lockfile.

Usage:

require 'lockfile'

l = LockFile.new("/Users/joshnesbitt/Desktop", "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

Testing

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.

Note on Patches/Pull Requests

  • 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.

Contributors

Copyright © 2010 Josh Nesbitt <josh@josh-nesbitt.net>. See LICENSE for details.

About

A simple implementation of a lock file class.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages