The queue event did two things: set the routing-changed flag, which the lifecycle event of the same change already sets, and deliver the leader-change info log. It cost an extra raft INSERT per connect/disconnect, two GetForLeaderElection reads per lifecycle event used for nothing else, a payload kind, a compaction key and a subscription-service method that only logged. The leader is now logged where it is published: the address-list emission logs the leader it just sent, and the routing rebuild logs one summary line with the leaders it published. Modules without election stay silent, as before. A future self-election needs a recompute trigger that also re-broadcasts the address list; that event will be added when the requirement exists, not carried as a no-op.
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package entity
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"isp-config-service/entity/xtypes"
|
|
)
|
|
|
|
type Event struct {
|
|
Id int `json:"id"`
|
|
Payload xtypes.Json[EventPayload] `json:"payload"`
|
|
}
|
|
|
|
func NewEvent(payload EventPayload) Event {
|
|
return Event{
|
|
Payload: xtypes.Json[EventPayload]{
|
|
Value: payload,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (e Event) Key() string {
|
|
switch {
|
|
case e.Payload.Value.ConfigUpdated != nil:
|
|
return fmt.Sprintf("config_updated_%s", e.Payload.Value.ConfigUpdated.ModuleId)
|
|
case e.Payload.Value.ModuleReady != nil:
|
|
return fmt.Sprintf("module_lifecycle_%s", e.Payload.Value.ModuleReady.ModuleId)
|
|
case e.Payload.Value.ModuleDisconnected != nil:
|
|
return fmt.Sprintf("module_lifecycle_%s", e.Payload.Value.ModuleDisconnected.ModuleId)
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
// nolint:tagliatelle
|
|
type EventPayload struct {
|
|
ConfigUpdated *PayloadConfigUpdated `json:",omitempty"`
|
|
ModuleReady *PayloadModuleReady `json:",omitempty"`
|
|
ModuleDisconnected *PayloadModuleDisconnected `json:",omitempty"`
|
|
}
|
|
|
|
type PayloadConfigUpdated struct {
|
|
ModuleId string
|
|
}
|
|
|
|
type PayloadModuleReady struct {
|
|
ModuleId string
|
|
}
|
|
|
|
type PayloadModuleDisconnected struct {
|
|
ModuleId string
|
|
}
|