Skip to content

Commit

Permalink
fix: Purge notifications properly
Browse files Browse the repository at this point in the history
Query the latest notification and clean notification by modified date.

Close #4682

Signed-off-by: bruce <weichou1229@gmail.com>
  • Loading branch information
weichou1229 committed Sep 20, 2023
1 parent b006ed3 commit 4482fa8
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 4482fa8

Please sign in to comment.