Skip to content

Commit

Permalink
Remove Travis, update files
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Apr 10, 2022
1 parent a06f6a8 commit d1a2cd2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
6 changes: 0 additions & 6 deletions .npmignore

This file was deleted.

4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"name": "node-graceful-shutdown",
"version": "1.1.1",
"version": "1.1.2",
"description": "Gracefully shutdown your modular NodeJS application",
"main": "index.js",
"files": [
"index.js",
"index.d.ts"
],
"engines": {
"node": ">=6"
},
Expand Down
39 changes: 21 additions & 18 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

[![npm](https://img.shields.io/npm/v/node-graceful-shutdown.svg)](https://www.npmjs.com/package/node-graceful-shutdown)
[![License](https://img.shields.io/github/license/zitros/node-graceful-shutdown.svg)](LICENSE)
[![Build Status](https://travis-ci.org/ZitRos/node-graceful-shutdown.svg?branch=master)](https://travis-ci.org/ZitRos/node-graceful-shutdown)
[![Build Status](https://img.shields.io/github/workflow/status/zitros/node-graceful-shutdown/Node.js%20package)](https://github.com/ZitRos/node-graceful-shutdown/actions/workflows/build-and-push.yaml)

Gracefully handle your modular NodeJS application's shutdown (termination), using dependencies.

Process signals captured: `SIGINT`, `SIGTERM`, `SIGQUIT`.

Example
-------
## Example

It doesn't matter in which order and where you define these graceful handlers, `node-graceful-shutdown` will
handle them appropriately and exit the process once all of them are processed.
Expand All @@ -19,17 +18,17 @@ import { onShutdown } from "node-graceful-shutdown";

// module1.js
onShutdown("http-server", async function () {
// Stop your http server here.
// Stop your http server here.
});

// module2.js
onShutdown("message-bus", ["http-server"], async function () {
// Close your RabbitMQ connection here ONLY AFTER http server's onShutdown completed.
// Close your RabbitMQ connection here ONLY AFTER http server's onShutdown completed.
});

// moduleX.js
onShutdown("database", ["http-server", "message-bus"], async function () {
// Shut down your database here, ONLY AFTER http-server and message-bus are completed.
// Shut down your database here, ONLY AFTER http-server and message-bus are completed.
});

// After all handlers are processed without errors, process exits with code 0.
Expand All @@ -44,39 +43,43 @@ this will work at its best in your application's `main.js`:

```javascript
import { onShutdown } from "node-graceful-shutdown";
import { startModule1, startModule2, stopModule1, stopModule2 /*, ...*/ } from "./src";
import {
startModule1,
startModule2,
stopModule1,
stopModule2 /*, ...*/,
} from "./src";

export const startMyApp = async () => {
await startModule1();
await startModule2();
await startModule1();
await startModule2();
};

export const stopMyApp = async () => {
// Stop modules one after another.
await stopModule1();
await stopModule2();
// ...
// Stop modules one after another.
await stopModule1();
await stopModule2();
// ...
};

// Handle application's shutdown.
onShutdown(stopMyApp);
```

Features and Guidelines
-----------------------
## Features and Guidelines

This library, along existing ones, allow your application to be **modular**. You define a cleanup callback in-place,
in the same module, where initialization happens. In addition, it allows specifying the order
in the same module, where initialization happens. In addition, it allows specifying the order

Recommendations:

1. Please, **do not use this module in libraries** (packages). It is intended for end applications only (see why in `5.`).
2. Once imported, `onShutdown` is application-wide (in terms of a single process), so the callbacks and their dependencies will see each other when imported from multiple files.
3. Circular shutdown handler dependencies will throw an error immediately once declared.
4. There's also an `onShutdownError` export which takes an error as an argument when any of assigned shutdown handlers throw an error (added for very-very prudent programmers only).
5. Importing this module **deletes** existing handlers (`SIGINT`, `SIGTERM`, `SIGQUIT`) if there are any. This is intended as other custom handlers can exit the process at any time.
6. You may also consider defining constants in your application, instead of string arguments (names).

Licence
-------
## Licence

[MIT](LICENSE) © [Nikita Savchenko](https://nikita.tk/developer)

0 comments on commit d1a2cd2

Please sign in to comment.