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

process-custodian

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

process-custodian

This package helps with organizing of tasks between few instances of same app, It can identify processes and track them activity.

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57
decreased by-65.66%
Maintainers
1
Weekly downloads
 
Created
Source

Process Custodian

This package helps with organizing of tasks between few instances of same app, It can identify processes and track them activity.

Installation


npm install process-custodian --save

How it works

This package gives collision-resistant fingerprint for each process. Process fingerprint has 6 char length with structure: (hostname - pid - random). So, It is optimized for horizontal scaling and binary search lookup performance.

After running init function, this package saves a heartbeat of process to the passed raw mongodb collection with frequency about tickTimeInSeconds (which default is 60s)

First of processes, which will be able to reserve self as a master, will be the master process to the moment of dead or lose master role if will be too busy to save in database a heartbeat at the time.

Example of use - with pure mongodb collection

import init from  'process-custodian';
import {MongoClient}  from 'mongodb'

MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {

  // Create a collection we want to drop later
  const collection = db.collection('process_custodian');

  const handle = init({rawCollection: collection, tickTimeInSeconds: 60});

  handle.onTick(() => {
    console.log('tick', handle.isMaster() ? 'master': 'slave')
  });
  
  handle.onIAmNewMaster(() => {
    console.log('I am master');
  });
  
  handle.onIAmSlave(() => {
    console.log('I am slave');
  });

Example of use - with meteor collection

import init from  'process-custodian';
// for meteor:
const collection = new Mongo.Collection('process_custodian');

const handle = init({
    rawCollection: collection.rawCollection(),
    tickTimeInSeconds: 60
});

handle.onTick(() => {
    console.log('tick', handle.isMaster() ? 'master': 'slave')
  });
  
handle.onIAmNewMaster(() => {
    console.log('I am master');
});
  
handle.onIAmSlave(() => {
    console.log('I am slave');
});

// if no necessery any more 
handle.stop();

Help tools

import init, {getFingerprint, humanize} from  'process-custodian';

//Getting fingerprint
console.log('id:', getFingerprint()); // e.g. output: id: ji4fmf
console.log('human:', humanize(getFingerprint())); // e.g. output: human: ji-4f-mf

FAQs

Package last updated on 07 Sep 2017

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