Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
// Handle SIGTERM (k8s, Docker stop) without dropping in-flight requestslet isShuttingDown = falseasyncfunctiongracefulShutdown(server: http.Server): Promise<void> {
console.log('SIGTERM received, starting graceful shutdown...')
isShuttingDown = true// Stop accepting new requests
server.close(async () => {
console.log('HTTP server closed')
try {
// Drain active jobsawait jobQueue.close()
// Close DB connectionsawait db.$disconnect()
// Close Redisawait redis.quit()
console.log('Graceful shutdown complete')
process.exit(0)
} catch (err) {
console.error('Error during shutdown:', err)
process.exit(1)
}
})
// Force kill after 30s if drain stallssetTimeout(() => {
console.error('Graceful shutdown timed out, forcing exit')
process.exit(1)
}, 30_000)
}
// Reject new requests during shutdown
app.use((_req, res, next) => {
if (isShuttingDown) {
res.setHeader('Connection', 'close')
return res.status(503).json({ error: 'Server is shutting down' })
}
next()
})
process.on('SIGTERM', () =>gracefulShutdown(server))
process.on('SIGINT', () =>gracefulShutdown(server))
Idempotency Keys
// Safe to retry without double-charging / double-creatingasyncfunctionprocessPaymentIdempotent(idempotencyKey: string,
payload: PaymentPayload): Promise<PaymentResult> {
const lockKey = `idempotency:${idempotencyKey}`// Check if already processedconst existing = await redis.get(lockKey)
if (existing) {
returnJSON.parse(existing) asPaymentResult
}
const result = await paymentGateway.charge(payload)
// Store result for 24 hoursawait redis.setex(lockKey, 86_400, JSON.stringify(result))
return result
}
// Client sends Idempotency-Key header, retry safe
router.post('/payments', async (req, res) => {
const key = req.headers['idempotency-key'] asstringif (!key) return res.status(400).json({ error: 'Idempotency-Key header required' })
const result = awaitprocessPaymentIdempotent(key, req.body)
res.json({ success: true, data: result })
})
Remember: Resilience is composed — combine circuit breaker + retry + bulkhead + timeout for defense in depth. Never apply retry without a circuit breaker, or you'll amplify load on a failing service.