GithubHelp home page GithubHelp logo

alexxnica / arsenal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scality/arsenal

0.0 1.0 0.0 1.14 MB

Common utilities for the open-source Scality S3 project components

License: Apache License 2.0

JavaScript 100.00%

arsenal's Introduction

Arsenal

CircleCI Scality CI

Common utilities for the S3 project components

Within this repository, you will be able to find the shared libraries for the multiple components making up the whole Project.

Guidelines

Please read our coding and workflow guidelines at scality/Guidelines.

Contributing

In order to contribute, please follow the Contributing Guidelines.

Shuffle

Usage

import { shuffle } from 'arsenal';

let array = [1, 2, 3, 4, 5];

shuffle(array);

console.log(array);

//[5, 3, 1, 2, 4]

Errors

Usage

import { errors } from 'arsenal';

console.log(errors.AccessDenied);

//{ [Error: AccessDenied]
//    code: 403,
//    description: 'Access Denied',
//    AccessDenied: true }

Clustering

The clustering class can be used to set up a cluster of workers. The class will create at least 1 worker, will log any worker event (started, exited). The class also provides a watchdog which restarts the workers in case of failure until the stop() method is called.

Usage

Simple

import { Clustering } from 'arsenal';

const cluster = new Clustering(clusterSize, logger);
cluster.start(current => {
    // Put here the logic of every worker.
    // 'current' is the Clustering instance, worker id is accessible by
    // current.getIndex()
});

The callback will be called every time a worker is started/restarted.

Handle exit

import { Clustering } from 'arsenal';

const cluster = new Clustering(clusterSize, logger);
cluster.start(current => {
    // Put here the logic of every worker.
    // 'current' is the Clustering instance, worker id is accessible by
    // current.getIndex()
}).onExit(current => {
    if (current.isMaster()) {
        // Master process exiting
    } else {
        const id = current.getIndex();
        // Worker (id) exiting
    }
});

You can handle exit event on both master and workers by calling the 'onExit' method and setting the callback. This allows release of resources or save state before exiting the process.

Silencing a signal

import { Clustering } from 'arsenal';

const cluster = new Clustering(clusterSize, logger);
cluster.start(current => {
    // Put here the logic of every worker.
    // 'current' is the Clustering instance, worker id is accessible by
    // current.getIndex()
}).onExit((current, signal) => {
    if (signal !== 'SIGTERM') {
        process.exit(current.getStatus());
    }
});

You can silence stop signals, by simply not exiting on the exit callback

Shutdown timeout

import { Clustering } from 'arsenal';

const cluster = new Clustering(clusterSize, logger, 1000);
cluster.start(current => {
    // Put here the logic of every worker.
    // 'current' is the Clustering instance, worker id is accessible by
    // current.getIndex()
}).onExit((current, signal) => {
    if (signal === 'SIGTERM') {
        // releasing resources
    }
});

By default, the shutdown timeout is set to 5000 milliseconds. This timeout is used only when you explicitly call the stop() method. This window is used to let the application release its resources, but if timeout occurs before the application has finished it's cleanup, a 'SIGKILL' signal is send to the process (which results in an immediate termination, and this signal can't be caught).

arsenal's People

Contributors

adrienverge avatar alex8092 avatar alexanderchan-scality avatar alexandre-merle avatar dora-korpar avatar electrachong avatar guillaumegomez avatar ironman-machine avatar jmunoznaranjo avatar joacchim avatar jonathan-gramain avatar laurenspiegel avatar mathieucassagne avatar nicolas2bert avatar philipyoo avatar ploki avatar rachedbenmustapha avatar rahulreddy avatar thibaultriviere avatar ttvi avatar vrancurel avatar yiurule avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.