Browse Source

En cours de développement

master
losyme 2 months ago
parent
commit
4bf9a077c0
  1. 49
      <Plug>_<Plug>_
  2. 6
      internal/storage/mongo/mongo.go

49
<Plug>_<Plug>_

@ -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
}
/*
######################################################################################################## @(°_°)@ #######
*/

6
internal/storage/mongo/mongo.go

@ -73,16 +73,16 @@ func New(cs *components.Components, cleanAfter time.Duration) (storage.Storage,
return ms, nil
}
func (ms *mongoStorage) Collection(name string) *mongo.Collection {
func (ms *mongoStorage) collection(name string) *mongo.Collection {
return ms.db.Collection(name)
}
func (ms *mongoStorage) cJobs() *mongo.Collection {
return ms.Collection("jobs")
return ms.collection("jobs")
}
func (ms *mongoStorage) cWorkflows() *mongo.Collection {
return ms.Collection("workflows")
return ms.collection("workflows")
}
func (ms *mongoStorage) State() (*storage.State, error) {

Loading…
Cancel
Save