From a653c87e6caae67c4fda5f3ed95ef95b57f28c6e Mon Sep 17 00:00:00 2001 From: Dennis Kleber Date: Wed, 21 Aug 2024 12:20:22 +0200 Subject: [PATCH] solves #174 --- dao/update_ticker.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dao/update_ticker.go b/dao/update_ticker.go index 79a0d93..478a23f 100644 --- a/dao/update_ticker.go +++ b/dao/update_ticker.go @@ -16,12 +16,14 @@ func UpdateTicker() { quit := make(chan struct{}) EventStateFinishTicker() EventStateClosedTicker() + UserActiveStateTicker() go func() { for { select { case <-ticker.C: EventStateFinishTicker() EventStateClosedTicker() + UserActiveStateTicker() case <-quit: ticker.Stop() return @@ -89,3 +91,24 @@ func EventStateClosedTicker() { } } + +func UserActiveStateTicker() { + checkDate := time.Now().Unix() - 15768000 + filter := bson.D{ + {Key: "last_login_date", Value: bson.D{{Key: "$lte", Value: checkDate}}}, + {Key: "active.status", Value: "confirmed"}, + } + userList := []models.User{} + pipeline := models.UserPipeline(false).Match(filter).Pipe + if err := UserCollection.Aggregate(context.Background(), pipeline, &userList); err != nil { + log.Print(err) + } + for _, user := range userList { + update := bson.D{{Key: "status", Value: "rejected"}} + userFilter := bson.D{{Key: "_id", Value: user.Active.ID}} + if err := ActiveCollection.UpdateOne(context.Background(), userFilter, vmdb.UpdateSet(update), nil); err != nil { + log.Print(err) + } + } + +}