2 changed files with 3 additions and 52 deletions
@ -1,49 +0,0 @@
|
||||
/* |
||||
------------------------------------------------------------------------------------------------------------------------ |
||||
####### dune ####### Copyright (c) 2021-2022 losyme ################################################ MIT License ####### |
||||
------------------------------------------------------------------------------------------------------------------------ |
||||
*/ |
||||
|
||||
package mongo |
||||
|
||||
import ( |
||||
"time" |
||||
|
||||
"forge.chapril.org/losyme/util" |
||||
"go.mongodb.org/mongo-driver/bson" |
||||
"go.mongodb.org/mongo-driver/mongo" |
||||
) |
||||
|
||||
func (ms *mongoStorage) Clean() error { |
||||
ctx, cancel := util.CtxWithTimeout(10 * time.Second) |
||||
defer cancel() |
||||
|
||||
session, err := ms.client.StartSession() |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
defer session.EndSession(ctx) |
||||
|
||||
_, err := session.WithTransaction( |
||||
ctx, |
||||
func(ctx mongo.SessionContext) (interface{}, error) { |
||||
_, err := ms.cJobs.DeleteMany( |
||||
ctx, |
||||
bson.M{ |
||||
"workflow": nil, |
||||
"finished_at": bson.M{"$lt": time.Now().Sub(ms.cleanAfter)}, |
||||
}, |
||||
) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
}, |
||||
) |
||||
|
||||
return err |
||||
} |
||||
|
||||
/* |
||||
######################################################################################################## @(°_°)@ ####### |
||||
*/ |
Loading…
Reference in new issue