0.0.1 • Published 10 years ago
ttlfs v0.0.1
ttlfs
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.
Usage
var ttlfs = require('ttlfs');
// check the ttl on a lock.
ttlfs.ttl('/tmp/awesome.lock', function(err, ttl) {
if (!ttl) {
// the lock has expired, we can create
// a new lock.
ttlfs.lock('my/tmp/awesome.lock', function(err) {
if (!err) {
console.log('we got a lock!');
}
});
}
});
// there is no need to check the ttl.
// an error will occur if the lock can't
// be fetched.
ttlfs.lock('/tmp/awesome.lock', function(err, ttl) {
if (!err) {
// do something with the lock.
} else {
// we could not get the lock.
}
});
Configuration
ttlfs accepts the following configuraiton settings:
- expiry: when, in ms, should the lock expire? default
60000
.
var ttlfs = require('ttlfs').configure({
expiry: 1800000
});
0.0.1
10 years ago