Skip to content

Commit

Permalink
added helper function to register all sagas contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
kopaygorodsky committed Apr 17, 2021
1 parent 188aa98 commit 34b6ab1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 1 addition & 9 deletions saga/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/go-foreman/foreman/log"
"github.com/go-foreman/foreman/pubsub/endpoint"
"github.com/go-foreman/foreman/pubsub/message"
"github.com/go-foreman/foreman/runtime/scheme"
"github.com/go-foreman/foreman/saga"
"github.com/go-foreman/foreman/saga/api/handlers/status"
"github.com/go-foreman/foreman/saga/contracts"
Expand Down Expand Up @@ -59,14 +58,7 @@ func (c Component) Init(mBus *brigadier.MessageBus) error {
eventHandler := handlers.NewEventsHandler(store, c.sagaMutex, mBus.SchemeRegistry(), opts.uidService, mBus.Logger())
sagaControlHandler := handlers.NewSagaControlHandler(store, c.sagaMutex, mBus.SchemeRegistry(), opts.uidService, mBus.Logger())

contractsList := []scheme.Object{
&contracts.StartSagaCommand{},
&contracts.RecoverSagaCommand{},
&contracts.CompensateSagaCommand{},
&contracts.SagaCompletedEvent{},
&contracts.SagaChildCompletedEvent{},
}
mBus.SchemeRegistry().AddKnownTypes(contracts.SystemGroup, contractsList...)
contracts.RegisterSagaContracts(mBus.SchemeRegistry())

mBus.Dispatcher().SubscribeForCmd(&contracts.StartSagaCommand{}, sagaControlHandler.Handle)
mBus.Dispatcher().SubscribeForCmd(&contracts.RecoverSagaCommand{}, sagaControlHandler.Handle)
Expand Down
14 changes: 13 additions & 1 deletion saga/contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@ import (
)

const (
SystemGroup scheme.Group = "systemSaga"
systemGroup scheme.Group = "systemSaga"
)

// RegisterSagaContracts registers all system saga contacts in specified scheme
func RegisterSagaContracts(scheme scheme.KnownTypesRegistry) {
scheme.AddKnownTypes(
systemGroup,
&StartSagaCommand{},
&RecoverSagaCommand{},
&CompensateSagaCommand{},
&SagaCompletedEvent{},
&SagaChildCompletedEvent{},
)
}

// StartSagaCommand once received will create SagaInstance, save it to Store and Start()
type StartSagaCommand struct {
message.ObjectMeta
Expand Down

0 comments on commit 34b6ab1

Please sign in to comment.