graceful-shutdown

Handle process signals and execute cleanup callbacks during application shutdown.

783|62|Updated Jan 19, 2026
One-click install
npx skills add https://github.com/dadbodgeoff/drift --skill graceful-shutdown-dadbodgeoff
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: graceful-shutdown
Source: https://github.com/dadbodgeoff/drift/tree/main/drift%20v1%20depreciated/skills/graceful-shutdown
Command: npx skills add https://github.com/dadbodgeoff/drift --skill graceful-shutdown-dadbodgeoff

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill ensures that your applications shut down cleanly, preventing data loss or corruption by managing in-flight jobs, draining buffers, and executing necessary cleanup tasks before termination.

Core Features & Use Cases

  • Signal Handling: Gracefully intercepts SIGTERM and SIGINT signals.
  • Job Tracking: Monitors and manages long-running tasks, ensuring they complete or time out.
  • Buffer Draining: Flushes any pending data in buffers before the process exits.
  • Cleanup Callbacks: Executes user-defined functions for final resource cleanup (e.g., closing database connections).
  • Use Case: When a background worker processing a critical queue receives a shutdown signal, this Skill ensures all currently processing items are finished and any buffered output is saved before the worker terminates.

Quick Start

Initialize the graceful shutdown handler and register signal handlers at the beginning of your application's entry point.

Frequently Asked Questions about graceful-shutdown

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle SIGTERM and SIGINT signals to prevent data loss during application shutdown?

To prevent data loss during application shutdown, you can handle SIGTERM and SIGINT signals by intercepting them to track in-flight asynchronous tasks, drain buffers, and execute resource cleanup callbacks before the process terminates.

What is the best way to drain buffers and close database connections before a Node.js or Python process exits?

The best way to drain buffers and close connections before exit is to register cleanup callbacks with a shutdown handler that intercepts process signals, ensuring pending data is flushed and final resource cleanup executes before termination.

How do you track in-flight asynchronous tasks to ensure they complete or time out when a worker receives a shutdown signal?

You track in-flight asynchronous tasks by registering them with a shutdown manager that monitors their status upon receiving a signal, ensuring they either complete successfully or time out before the application terminates.

Does this graceful shutdown handler support both TypeScript and Python environments?

Yes, this graceful shutdown handler supports both TypeScript/JavaScript and Python environments, allowing you to manage orderly application termination, signal handling, and resource cleanup across both tech stacks.

Why do background workers lose queued items when terminating, and how can I ensure processing finishes?

Background workers lose queued items when terminating because pending tasks are abruptly killed. You can ensure processing finishes by using a shutdown handler to intercept signals, track active jobs, and wait for them to complete before exiting.