Skip to content

Commit

Permalink
Merge pull request #4686 from weichou1229/issue-4682
Browse files Browse the repository at this point in the history
fix: Purge notifications properly
  • Loading branch information
cloudxxx8 authored Sep 21, 2023
2 parents 4f9cf71 + 4482fa8 commit fd2f36c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/infrastructure/redis/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func (c *Client) DeleteProcessedNotificationsByAge(age int64) (err errors.EdgeX)
}

func latestNotificationByOffset(conn redis.Conn, offset int) (notification models.Notification, edgeXerr errors.EdgeX) {
objects, err := getObjectsByRevRange(conn, NotificationCollectionCreated, offset, 1)
objects, err := getObjectsByRevRange(conn, NotificationCollection, offset, 1)
if err != nil {
return notification, errors.NewCommonEdgeXWrapper(err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/support/notifications/application/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,13 @@ func purgeNotification(dic *di.Container) errors.EdgeX {
}
if total >= config.Retention.MaxCap {
lc.Debugf("Purging the notification amount %d to the minimum capacity %d", total, config.Retention.MinCap)
// Query the latest notification and clean notifications by modified date.
notification, err := dbClient.LatestNotificationByOffset(config.Retention.MinCap)
if err != nil {
return errors.NewCommonEdgeX(errors.Kind(err), fmt.Sprintf("failed to query notification with offset '%d'", config.Retention.MinCap), err)
}
now := time.Now().UnixMilli()
age := now - notification.Created
age := now - notification.Modified
err = dbClient.CleanupNotificationsByAge(age)
if err != nil {
return errors.NewCommonEdgeX(errors.Kind(err), fmt.Sprintf("failed to delete notifications and transmissions by age '%d'", age), err)
Expand Down

0 comments on commit fd2f36c

Please sign in to comment.