testing promotion actions
All checks were successful
Build and Publish / Metadata (push) Successful in 10s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m16s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m19s

This commit is contained in:
matst80
2025-10-20 20:58:34 +02:00
parent 246a5ebd85
commit 9ecd91c163
3 changed files with 57 additions and 17 deletions

View File

@@ -15,11 +15,32 @@ type ApplyResult struct {
Error error `json:"error,omitempty"`
}
type MutationProcessor interface {
Process(grain any) error
}
type BasicMutationProcessor[V any] struct {
processor func(any) error
}
func NewMutationProcessor[V any](process func(V) error) MutationProcessor {
return &BasicMutationProcessor[V]{
processor: func(v any) error {
return process(v.(V))
},
}
}
func (p *BasicMutationProcessor[V]) Process(grain any) error {
return p.processor(grain)
}
type MutationRegistry interface {
Apply(grain any, msg ...proto.Message) ([]ApplyResult, error)
RegisterMutations(handlers ...MutationHandler)
Create(typeName string) (proto.Message, bool)
GetTypeName(msg proto.Message) (string, bool)
RegisterProcessor(processor ...MutationProcessor)
//GetStorageEvent(msg proto.Message) StorageEvent
//FromStorageEvent(event StorageEvent) (proto.Message, error)
}
@@ -27,6 +48,7 @@ type MutationRegistry interface {
type ProtoMutationRegistry struct {
mutationRegistryMu sync.RWMutex
mutationRegistry map[reflect.Type]MutationHandler
processors []MutationProcessor
}
var (
@@ -114,9 +136,14 @@ func NewMutationRegistry() MutationRegistry {
return &ProtoMutationRegistry{
mutationRegistry: make(map[reflect.Type]MutationHandler),
mutationRegistryMu: sync.RWMutex{},
processors: make([]MutationProcessor, 0),
}
}
func (r *ProtoMutationRegistry) RegisterProcessor(processors ...MutationProcessor) {
r.processors = append(r.processors, processors...)
}
func (r *ProtoMutationRegistry) RegisterMutations(handlers ...MutationHandler) {
r.mutationRegistryMu.Lock()
defer r.mutationRegistryMu.Unlock()
@@ -198,6 +225,12 @@ func (r *ProtoMutationRegistry) Apply(grain any, msg ...proto.Message) ([]ApplyR
results = append(results, ApplyResult{Error: err, Type: rt.Name(), Mutation: m})
}
for _, processor := range r.processors {
err := processor.Process(grain)
if err != nil {
return results, err
}
}
return results, nil
}