A semaphore handler for Node.js and MySQL. Allows you to generate a semaphore in a clustered Node.js environment using MySQL. This is useful for such things as cron jobs or long running tasks that you only want to occur on a single instance.
Requirements: MySQL server
Installation
npm install mysql-semaphore --save
Initialization:
Refer to node-mysql (https://github.com/felixge/node-mysql/) for MySql configuration settings.
var Semaphore = require;var semaphore = new Semaphore;
Before You Begin:
Be aware that this library requires that the lock name be unique for a particular usage. If another application uses the same lock name, a lock could be inadvertantly unlocked. It is recommended that the lock name include application and database name and usage to ensure uniqueness - for example: mydb_myapp_myprocess as the lockName parameter.
Methods:
Get Lock
semaphore.lock //test is the lock name .then
Release Lock
semaphore.unlock //test is the lock name .then .catch;
Check If Locked
semaphore.islocked //test is the lock name .then .catch
Tests:
npm test