mirror of
https://github.com/boshu2/agentops.git
synced 2026-09-14 15:08:13 +08:00
5 lines
1.5 KiB
JSON
5 lines
1.5 KiB
JSON
{"type":"user","sessionId":"test-session-001","timestamp":"2026-01-24T10:00:00.000Z","uuid":"msg-001","message":{"role":"user","content":"How should we handle graceful shutdown in our Go service?"}}
|
|
{"type":"assistant","sessionId":"test-session-001","timestamp":"2026-01-24T10:00:15.000Z","uuid":"msg-002","parentUuid":"msg-001","message":{"role":"assistant","content":"For graceful shutdown in Go services, I recommend using context.WithCancel. Here's why:\n\n**Decision:** Use context.WithCancel for graceful shutdown\n\n**Rationale:**\n1. All goroutines can check ctx.Done() to know when to stop\n2. It integrates well with Go's standard library\n3. Timeouts can be layered with context.WithTimeout\n\n**Implementation:**\n```go\nctx, cancel := context.WithCancel(context.Background())\ndefer cancel()\n\n// Pass ctx to all goroutines\ngo worker(ctx)\n\n// On SIGTERM/SIGINT\nsignal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)\n<-sigChan\ncancel() // Triggers graceful shutdown\n```\n\nThis pattern ensures clean termination of all background work."}}
|
|
{"type":"user","sessionId":"test-session-001","timestamp":"2026-01-24T10:01:00.000Z","uuid":"msg-003","parentUuid":"msg-002","message":{"role":"user","content":"That makes sense. Let's use that approach."}}
|
|
{"type":"assistant","sessionId":"test-session-001","timestamp":"2026-01-24T10:01:10.000Z","uuid":"msg-004","parentUuid":"msg-003","message":{"role":"assistant","content":"Perfect. I'll implement the graceful shutdown pattern with context.WithCancel. This is a well-established Go idiom that will serve us well."}}
|