qfslock

0.9.1 • Public • Published

qfslock

Build Status Coverage Status

Set filesystem advisory locks containing the process-id of the owning process. No dependencies.

fslock = require('qfslock');

fslock.setLock('/var/lock/my.lock', process.pid);
// fs.existsSync('/var/lock/my.lock') => true

fslock.clearLock('/var/lock/my.lock', process.pid);
// fs.existsSync('/var/lock/my.lock') => false

Api

fslock.FsLock( )

Implementation class. The package functions are calls to an internal singleton.

fslock.setLock( locfile, pid )

Atomically create the file lockfile with contents pid. It is an error if a lockfile already exists containing a pid other then the pid setLock was called with.

fslock.clearLock( lockfile, pid )

Remove the file lockfile if it contains pid or if it belongs to a process that does not exist any more. Note that a process that is not ours will appears to not exist, but its lockfile will not have the right permissions to be removed by us.

fslock.processNotExists( pid )

Helper function that tests whether a process has already exited, or is still running. Returns true if process id pid does not exist, and false otherwise. Non-numeric process-ids do not exist.

Change Log

  • 0.9.1 - added license file
  • 0.9.0 - split out from qworker and refactored into a class

Package Sidebar

Install

npm i qfslock

Weekly Downloads

2

Version

0.9.1

License

Apache-2.0

Unpacked Size

9.55 kB

Total Files

6

Last publish

Collaborators

  • andrasq