Skip to content

[BE-89] Graceful shutdown and Bull queue drain #1477

Description

@yusuftomilola

Overview

main.ts does not enable shutdown hooks. On deploy or restart, in-flight HTTP requests and running Bull jobs are killed mid-execution, which can leave payments and invoices half-processed.

Tasks

  • Call app.enableShutdownHooks() and handle SIGTERM/SIGINT.
  • Stop accepting new connections, then wait for in-flight requests up to a configurable timeout.
  • Implement OnModuleDestroy in queue-consuming modules to let active jobs finish and close the Bull connection cleanly.
  • Close the TypeORM connection and Redis clients explicitly.
  • Log each shutdown phase so a stuck shutdown is diagnosable.

Acceptance Criteria

  • Sending SIGTERM during an active request completes that request before exit.
  • An in-progress Bull job either finishes or is returned to the queue — never silently lost.
  • The process exits within the configured timeout rather than hanging.

Notes for Contributors

Comment below to be assigned.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions