Part of Zenko CloudServer strangely extracted into a separate library
 
 
Go to file
Vitaliy Filippov 19855115ae Use TS? 2024-08-06 19:56:20 +03:00
.github gha: bump codecov v4 2024-07-10 18:45:22 +02:00
documentation ARSN-410: update bucketInfo and md 2024-04-30 17:16:50 +02:00
lib Use TS? 2024-08-06 19:56:20 +03:00
tests Merge remote-tracking branch 'origin/w/7.70/bugfix/ARSN-425-listingLatestCrashWithUndefined' into w/8.1/bugfix/ARSN-425-listingLatestCrashWithUndefined 2024-07-08 11:28:59 -07:00
.eslintrc bump eslint dependency 2023-04-13 15:14:30 -07:00
.gitignore ARSN-67 Add TypeScript and Babel, and make test suite working 2022-03-24 15:02:16 +01:00
.npmignore ARSN-67 Remove ignore of build for NPM 2022-03-24 15:02:16 +01:00
.swcrc Use swc to transpile during installation 2024-08-04 00:00:10 +03:00
.yamllint (YML) - Add the yaml linter 2016-02-03 11:23:38 +01:00
CONTRIBUTING.md Add Contribution rules 2016-06-08 20:58:31 +02:00
LICENSE Update OSS License 2016-06-08 19:31:49 +02:00
README.md feature: ZENKO-3266 Code Coverage Tracking 2021-02-19 14:21:30 -08:00
babel.config.js ARSN-67 Add TypeScript and Babel, and make test suite working 2022-03-24 15:02:16 +01:00
circle.yml feature: Update node version 2018-03-26 12:52:48 +02:00
greenkeeper.json Merge remote-tracking branch 'origin/w/7.8/dependabot/npm_and_yarn/development/7.4/lolex-6.0.0' into w/8.1/dependabot/npm_and_yarn/development/7.4/lolex-6.0.0 2020-07-20 17:41:42 -07:00
index.ts ARSN-406: add request context options for quota evaluation 2024-05-02 09:00:00 +02:00
package.json Use swc to transpile during installation 2024-08-04 00:00:10 +03:00
tsconfig.json Use TS? 2024-08-06 19:56:20 +03:00

README.md

Arsenal

codecov

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).