Skip to content

Commit

Permalink
refactor: save state to store interface
Browse files Browse the repository at this point in the history
  • Loading branch information
w-h-a committed Aug 25, 2024
1 parent 426657b commit 66ff5b2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions sidecar/custom/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ func (s *customSidecar) OnEventPublished(event *sidecar.Event) error {
return err
}

func (s *customSidecar) SaveStateToStore(storeId string, state []*store.Record) error {
if len(state) == 0 {
func (s *customSidecar) SaveStateToStore(state *sidecar.State) error {
if len(state.Records) == 0 {
return nil
}

st, ok := s.options.Stores[storeId]
st, ok := s.options.Stores[state.StoreId]
if !ok {
return nil
}

for _, record := range state {
for _, record := range state.Records {
if err := st.Write(record); err != nil {
return err
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func (s *customSidecar) String() string {

func (s *customSidecar) actOnEventFromApp(event *sidecar.Event) error {
if event.State != nil && len(event.State.Records) > 0 {
if err := s.SaveStateToStore(event.State.StoreId, event.State.Records); err != nil {
if err := s.SaveStateToStore(event.State); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion sidecar/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
type Sidecar interface {
Options() SidecarOptions
OnEventPublished(event *Event) error
SaveStateToStore(store string, state []*store.Record) error
SaveStateToStore(state *State) error
RetrieveStateFromStore(store, key string) ([]*store.Record, error)
ReadEventsFromBroker(broker string)
UnsubscribeFromBroker(broker string) error
Expand Down

0 comments on commit 66ff5b2

Please sign in to comment.