Code Monkey home page Code Monkey logo

filelock's Introduction

Filelock Build Status

Heavily tested, but simple filelocking solution using flock command. It guarantees unlocking of files.

It works for sure on MRI 1.8, 1.9, 2.0, JRuby in both 1.8 and 1.9 mode, and Rubinius.

This gem doesn't support NFS. You can use it with GlusterFS, though.

Usage

Filelock '/tmp/path/to/lock' do
  # do blocking operation
end

You can also pass the timeout for blocking operation (default is 60 seconds):

Filelock '/tmp/path/to/lock', :timeout => 10 do
  # do blocking operation
end

You can also pass a wait timeout for grabbing the lock (default is 60 seconds):

Filelock '/tmp/path/to/lock', :wait => 10 do
  # do blocking operation
end

Note that lock file directory must already exist, and lock file is not removed after unlock.

FAQ

Does it support NFS?

No. You can use more complex lockfile gem if you want to support NFS.

The code is so short. Why shouln't I just copy-paste it?

Because even such short code can have issues in future. File locking is very fragile operation. You may expect new releases of this gem fixing discovered bogus behavior (or introducing awesome features).

You are encouraged to use it if you develop gem that uses flock command, and care about running it on different ruby versions and platforms. Each has its own quirks with regard to flock command.

How it's different from lockfile gem?

Lockfile is filelocking solution handling NFS filesystems, based on homemade locking solution. Filelock uses flock UNIX command to handle filelocking on very low level. Also lockfile allows you to specify retry timeout. In case of Ruby's flock command this is hard-cored to 0.1 seconds.

How it's different from cleverua-lockfile gem?

Cleverua removes lockfile after unlocking it. Thas has been proven fatal both in my tests and in filelocking advices from the Internet. You could try find a way to remove lock file without breaking Filelock tests. I will be glad to accept such pull-request.

Contribute

Try to break Filelock in some way (note it doesn't support NFS).

License

Filelock is MIT-licensed. You are awesome.

filelock's People

Contributors

fermuch avatar jasonwbarnett avatar sheerun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.