Skip to content

[ENHANCEMENT] Pass Context down when using Visitor for EventSummary #2132

@jcscottiii

Description

@jcscottiii

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.

// 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

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions