-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Labels
enhancementNew feature or requestNew feature or request
Description
When parsing the EventSummary, we don't pass down the context which could be helpful when shutting down the service to cancel outstanding requests to things like the database.
webstatus.dev/lib/workertypes/types.go
Lines 75 to 106 in b508c57
| // SummaryVisitor defines the contract for consuming immutable Event Summaries. | |
| // Unlike state blobs which are migrated to the latest schema, summaries are | |
| // historical records that should be rendered as-is. The Visitor pattern forces | |
| // consumers to explicitly handle each schema version (e.g. V1, V2) independently. | |
| type SummaryVisitor interface { | |
| VisitV1(s EventSummary) error | |
| } | |
| // ParseEventSummary handles the version detection and dispatching logic. | |
| // Consumers (like the Delivery Worker) should use this instead of raw json.Unmarshal. | |
| func ParseEventSummary(data []byte, v SummaryVisitor) error { | |
| // 1. Peek at version | |
| var header struct { | |
| SchemaVersion string `json:"schemaVersion"` | |
| } | |
| if err := json.Unmarshal(data, &header); err != nil { | |
| return fmt.Errorf("invalid summary json: %w", err) | |
| } | |
| // 2. Dispatch | |
| switch header.SchemaVersion { | |
| case VersionEventSummaryV1: | |
| var s EventSummary | |
| if err := json.Unmarshal(data, &s); err != nil { | |
| return fmt.Errorf("failed to parse v1 summary: %w", err) | |
| } | |
| return v.VisitV1(s) | |
| default: | |
| return fmt.Errorf("unknown summary version: %q", header.SchemaVersion) | |
| } | |
| } |
We should pass the context down
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Status
No status