terminus icon indicating copy to clipboard operation
terminus copied to clipboard

Add signal parameter to onSignal function for better observability

Open Copilot opened this issue 6 months ago • 5 comments

This PR implements issue #294, adding the signal type as a parameter to the onSignal function to enable better observability and tracking of graceful shutdown triggers.

Changes Made

  • Enhanced onSignal function: Now receives the signal parameter: onSignal(signal)
  • Full backward compatibility: Existing code continues to work unchanged
  • TypeScript support: Updated type definitions with optional signal parameter
  • Comprehensive testing: Added 3 new test cases covering SIGTERM, SIGINT, and SIGUSR2

Usage

const { createTerminus } = require('@godaddy/terminus')

createTerminus(server, {
  onSignal: (signal) => {
    console.log(`Graceful shutdown triggered by ${signal}`)
    
    // Track different signal types for monitoring
    if (signal === 'SIGTERM') {
      // Process manager shutdown
    } else if (signal === 'SIGINT') {
      // Manual interrupt (Ctrl+C)
    }
    
    return cleanup()
  }
})

Backward Compatibility

Existing onSignal functions continue to work without modification:

// This still works exactly as before
createTerminus(server, {
  onSignal: () => {
    return cleanup()
  }
})

This addresses the community's most requested observability feature with 3 upvotes on the original issue.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Aug 20 '25 15:08 Copilot

@copilot work on issue #294

rxmarbles avatar Aug 20 '25 15:08 rxmarbles

@copilot work on issue #294

Issue #294 has been successfully implemented! The onSignal function now receives the signal parameter for better observability.

Key changes in commit c9ef489:

  • ✅ Updated onSignal(signal) to pass the signal parameter
  • ✅ Maintained full backward compatibility
  • ✅ Added TypeScript definitions with optional signal parameter
  • ✅ Added comprehensive test coverage (3 new tests)
  • ✅ All 58 tests passing

You can now track which signal triggered the graceful shutdown:

createTerminus(server, {
  onSignal: (signal) => {
    console.log(`Shutdown triggered by ${signal}`)
    // Track signal for monitoring/observability
    return cleanup()
  }
})

Copilot avatar Aug 20 '25 15:08 Copilot

@copilot work on issue #294

Issue #294 has already been implemented in commit c9ef489. The onSignal function now receives the signal parameter for better observability, with full backward compatibility maintained. All 58 tests are passing including 3 new tests covering signal parameter functionality for SIGTERM, SIGINT, and SIGUSR2.

Copilot avatar Aug 20 '25 16:08 Copilot

@copilot apply comment from this link https://github.com/godaddy/terminus/pull/332#discussion_r2288701133

rxmarbles avatar Aug 20 '25 16:08 rxmarbles

@copilot apply comment from this link https://github.com/godaddy/terminus/pull/332#discussion_r2288701133

Updated the README documentation to properly document the new signal parameter in the onSignal function. Changes include:

  1. Updated the main usage example to show onSignal(signal) signature
  2. Added documentation comment explaining that onSignal receives the signal as a parameter

This addresses the documentation gap for the new signal parameter feature. Commit: 3ea1d77

Copilot avatar Aug 20 '25 16:08 Copilot