Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hemerajs/fastify-graceful-shutdown
Gracefully shutdown fastify
https://github.com/hemerajs/fastify-graceful-shutdown
fastify fastifyjs-plugin graceful
Last synced: 4 days ago
JSON representation
Gracefully shutdown fastify
- Host: GitHub
- URL: https://github.com/hemerajs/fastify-graceful-shutdown
- Owner: hemerajs
- License: mit
- Created: 2017-09-24T11:43:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-08-30T05:42:52.000Z (5 months ago)
- Last Synced: 2025-01-15T06:58:14.379Z (11 days ago)
- Topics: fastify, fastifyjs-plugin, graceful
- Language: JavaScript
- Size: 1.27 MB
- Stars: 74
- Watchers: 4
- Forks: 13
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fastify - `fastify-graceful-shutdown`
README
# 🏹 fastify-graceful-shutdown
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](#badge)
[![NPM version](https://img.shields.io/npm/v/fastify-graceful-shutdown.svg?style=flat)](https://www.npmjs.com/package/fastify-graceful-shutdown)Shutdown [Fastify](https://github.com/fastify/fastify) graceful asynchronously. By default the fastify `close` hook is called when `SIGINT` or `SIGTERM` was triggered.
## Features
- Graceful and debug friendly shutdown
- Flush the fastify logger before process exit to avoid losing logs
- Handlers are called in parallel for faster shutdown## Install
```bash
npm install --save fastify-graceful-shutdown
```## Register plugin
```js
fastify.register(require('fastify-graceful-shutdown'))
```## Usage
```js
fastify.after(() => {
fastify.gracefulShutdown(async (signal) => {
fastify.log.info('Received signal to shutdown: %s', signal)
await doSomethingAsync()
})
})
```## Compatibility
Fastify >=3
## Caveats
- Don't register signal handlers otherwise except with this plugin.
- Can't be used with a different logger other than [Pino](https://github.com/pinojs/pino) because we use the child logger feature to encapsulate the logs.
- Use fastify `onClose` hook to release resources in your plugin.
- The process will be exited after a certain timeout (Default 10 seconds) to protect against stuck process.