Skip to content

Commit

Permalink
Merge pull request #39 from chauberahul1993/ODIM-6136_task
Browse files Browse the repository at this point in the history
ODIM-6136: Persist event enabled
  • Loading branch information
amar-shalgar authored Jun 27, 2022
2 parents 6757013 + 6787c0d commit 6cd1462
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
5 changes: 0 additions & 5 deletions svc-events/evcommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ import (
"github.com/ODIM-Project/ODIM/svc-events/evresponse"
)

const (
// SaveUndeliveredEventsFlag holds the value to check if UndeliveredEvents need to be saved in DB
SaveUndeliveredEventsFlag = false
)

//StartUpInteraface Holds the function pointer of external interface functions
type StartUpInteraface struct {
DecryptPassword func([]byte) ([]byte, error)
Expand Down
40 changes: 16 additions & 24 deletions svc-events/events/publishevttosubscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,14 @@ func (e *ExternalInterfaces) postEvent(destination, eventUniqueID string, event
if err == nil {
resp.Body.Close()
log.Info("Event is successfully forwarded")
if evcommon.SaveUndeliveredEventsFlag {
// check any undelivered events are present in db for the destination and publish those
go e.checkUndeliveredEvents(destination)
}
// check any undelivered events are present in db for the destination and publish those
go e.checkUndeliveredEvents(destination)
return
}
undeliveredEventID := destination + ":" + eventUniqueID
if evcommon.SaveUndeliveredEventsFlag {
serr := e.SaveUndeliveredEvents(undeliveredEventID, event)
if serr != nil {
log.Error("error while saving undelivered event: ", serr.Error())
}
serr := e.SaveUndeliveredEvents(undeliveredEventID, event)
if serr != nil {
log.Error("error while saving undelivered event: ", serr.Error())
}
go e.reAttemptEvents(destination, undeliveredEventID, event)
return
Expand Down Expand Up @@ -379,27 +375,23 @@ func (e *ExternalInterfaces) reAttemptEvents(destination, undeliveredEventID str
for i := 0; i < count; i++ {
log.Info("Retry event forwarding on destination: ", destination)
time.Sleep(time.Second * time.Duration(config.Data.EventConf.DeliveryRetryIntervalSeconds))
if evcommon.SaveUndeliveredEventsFlag {
// if undelivered event already published then ignore retrying
eventString, err := e.GetUndeliveredEvents(undeliveredEventID)
if err != nil || len(eventString) < 1 {
log.Info("Event is forwarded to destination")
return
}
// if undelivered event already published then ignore retrying
eventString, err := e.GetUndeliveredEvents(undeliveredEventID)
if err != nil || len(eventString) < 1 {
log.Info("Event is forwarded to destination")
return
}
resp, err = sendEvent(destination, event)
if err == nil {
resp.Body.Close()
log.Info("Event is successfully forwarded")
if evcommon.SaveUndeliveredEventsFlag {
// if event is delivered then delete the same which is saved in 1st attempt
err = e.DeleteUndeliveredEvents(undeliveredEventID)
if err != nil {
log.Error("error while deleting undelivered events: ", err.Error())
}
// check any undelivered events are present in db for the destination and publish those
go e.checkUndeliveredEvents(destination)
// if event is delivered then delete the same which is saved in 1st attempt
err = e.DeleteUndeliveredEvents(undeliveredEventID)
if err != nil {
log.Error("error while deleting undelivered events: ", err.Error())
}
// check any undelivered events are present in db for the destination and publish those
go e.checkUndeliveredEvents(destination)
return
}

Expand Down

0 comments on commit 6cd1462

Please sign in to comment.