Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

enrise-lock

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enrise-lock

Lock functionality used within Enrise projects and module's

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Node.js lock module

build:? Coverage Status dependencies:? devDependencies:?

An elasticsearch based lock mechanism for resources and ownership.

Introduction

This module provides abstraction methods to lock a resource with an owner. The owner is the name of the process requesting a lock. The resource would be the specific element/index/endpoint/etc.. that requires locking.

Installation

NPM: npm install enrise-lock --save
Yarn: yarn add enrise-lock

Initialization

Require and instantiate the locker. const lock = new require('enrise-lock')(config: Object);

Where config is an object with the following options. Type is optional, the rest is mandatory.

  • esClient: elasticsearch: An elasticsearch client for the lock module to use. This can either be an elasticsearch or an enrise-esclient instance.
  • index: String: The elasticsearch index that will be used to store all lock-documents.
  • owner: String: The name of the process that is looking to place the lock.
  • [type: String]: The index-type that will be used to store all lock-documents. This will default to 'lockdocument'.

Usage and API methods

lock.acquire(resource: String, callback: function)

Set a lock for resource: resource. Callback will be called with parameters [err, success: boolean]. The success paramater will be false if a lock already exists.

lock.release(resource: String, callback: function)

Release a lock for resource: resource. Callback will be called with parameter [err].

lock.isLocked(resource: String, callback: function)

Check if a resource is locked. Callback will be called with parameters [err, isLocked: boolean].

lock.list(callback: function)

Retrieve a list of all current locks. Callback will be called with parameters [err, locks: Object]. Where the key in locks represents the resource and the value an object with the owner.

lock.delete(callback: function)

Delete the entire lock-index. Callback will be called with parameter [err].

Example

const lock = new require('enrise-lock')({
  esClient: new require('elasticsearch').Client(),
  index: 'globallock',
  type: 'lockdocument',
  owner: 'api'
});

// Set lock
lock.acquire('my-resource', (err, success) => {
  // Do some asynchronous operation
  // ...

  // Release lock
  lock.release('my-resource', (err, success) => {
  	// ...
  });
});

FAQs

Package last updated on 23 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc