A file-system-based mutex, with a TTL.
Create a lock-file with a TTL.
what is it good for?
When you want to perform an operation only once in a given block of time, from a single process, on a single server, e.g., during an NRPE check.
what isn't it good for?
When you have multiple processes, in parallel, attempting to acquire a lock.
var ttlfs = require'ttlfs';// check the ttl on a lock.ttlfsttl'/tmp/awesome.lock'if !ttl// the lock has expired, we can create// a new lock.ttlfslock'my/tmp/awesome.lock'if !errconsole.log'we got a lock!';;;// there is no need to check the ttl.// an error will occur if the lock can't// be fetched.ttlfslock'/tmp/awesome.lock'if !err// do something with the lock.else// we could not get the lock.;
ttlfs accepts the following configuraiton settings:
- expiry: when, in ms, should the lock expire? default
var ttlfs = require'ttlfs'configureexpiry: 1800000;