mirror of
https://github.com/directus/directus.git
synced 2026-02-13 14:54:58 -05:00
* Start setting up @directus/pressure * Build pressure middleware * Add basic readme * Install @directus/pressure * Fix this binding * Experiment * Add defaults util * Cleanup * Fix export * Use directus defaults * Start tests * Add random-utils package * Finish testing for monitor * Add prod deployment * Stop building test files in prod * My favorite * Integrate pressure handler * Add decent defaults * Add retry header + custom error support * Clean-up merge conflict & sort imports * Fix build * Remove default value for retry after * Verify sampleInterval value * ran eslint * updated package lock * updated vitest * Create slimy-zebras-jam.md * Added basic docs for config options * updated pnpm lock and changeset * Update & align new packages * Update .changeset/slimy-zebras-jam.md --------- Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch> Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> Co-authored-by: Brainslug <tim@brainslug.nl>
@directus/pressure
Installation
npm install @directus/pressure
Usage
Standalone
The pressure monitor is a class that can be used anywhere:
import { PressureMonitor } from '@directus/pressure';
const monitor = new PressureMonitor({
maxEventLoopUtilization: 0.8,
});
monitor.overloaded; // true | false
Express
The library also exports an express middleware that can be used to throw an Error when the pressure monitor reports overloaded:
import express from 'express';
import { handlePressure } from '@directus/pressure';
const app = express();
app.use(
handlePressure({
maxEventLoopUtilization: 0.8,
})
);