Skip to content

Commit

Permalink
feat: delete
Browse files Browse the repository at this point in the history
  • Loading branch information
w-h-a committed Aug 28, 2024
1 parent 96f3011 commit 115204c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
63 changes: 40 additions & 23 deletions sidecar/custom/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ func (s *customSidecar) Options() sidecar.SidecarOptions {
return s.options
}

func (s *customSidecar) OnEventPublished(event *sidecar.Event) error {
var err error

if len(event.To) > 0 {
err = s.actOnEventFromApp(event)
} else {
err = s.postEventToApp(event)
}

return err
}

func (s *customSidecar) SaveStateToStore(state *sidecar.State) error {
if len(state.Records) == 0 {
return nil
Expand Down Expand Up @@ -90,6 +78,31 @@ func (s *customSidecar) RetrieveStateFromStore(storeId, key string) ([]*store.Re
return recs, nil
}

func (s *customSidecar) RemoveStateFromStore(storeId, key string) error {
st, ok := s.options.Stores[storeId]
if !ok {
return nil
}

if err := st.Delete(key); err != nil {
return err
}

return nil
}

func (s *customSidecar) OnEventPublished(event *sidecar.Event) error {
if len(event.To) == 0 {
return nil
}

if err := s.actOnEventFromApp(event); err != nil {
return err
}

return nil
}

func (s *customSidecar) ReadEventsFromBroker(brokerId string) {
bk, ok := s.options.Brokers[brokerId]
if !ok {
Expand Down Expand Up @@ -163,13 +176,15 @@ func (s *customSidecar) actOnEventFromApp(event *sidecar.Event) error {
}
}

if len(event.To) > 0 {
if len(event.Concurrent) > 0 {
s.sendEventToTargetsConcurrently(event)
} else {
if err := s.sendEventToTargetsSequentially(event); err != nil {
return err
}
if len(event.To) == 0 {
return nil
}

if len(event.Concurrent) > 0 {
s.sendEventToTargetsConcurrently(event)
} else {
if err := s.sendEventToTargetsSequentially(event); err != nil {
return err
}
}

Expand Down Expand Up @@ -242,10 +257,12 @@ func (s *customSidecar) postEventToApp(event *sidecar.Event) error {
}
}

if rsp != nil {
if err := s.actOnEventFromApp(rsp); err != nil {
return err
}
if rsp == nil {
return nil
}

if err := s.actOnEventFromApp(rsp); err != nil {
return err
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion sidecar/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

type Sidecar interface {
Options() SidecarOptions
OnEventPublished(event *Event) error
SaveStateToStore(state *State) error
RetrieveStateFromStore(store, key string) ([]*store.Record, error)
RemoveStateFromStore(store, key string) error
OnEventPublished(event *Event) error
ReadEventsFromBroker(broker string)
UnsubscribeFromBroker(broker string) error
String() string
Expand Down

0 comments on commit 115204c

Please sign in to comment.