Browse Source

En cours de développement

master
losyme 2 months ago
parent
commit
cc5530d2c5
  1. 4
      internal/storage/mongo/jobs.go
  2. 33
      internal/storage/mongo/workflows.go

4
internal/storage/mongo/jobs.go

@ -82,6 +82,10 @@ func (ms *mongoStorage) InsertJob(job *jw.Job) (bool, error) {
return ms.maybeInsertJob(ctx, job)
}
func (ms *mongoStorage) txUpdateJob(ctx mongo.SessionContext, job *jw.Job) error {
return ms.cJobs().FindOneAndReplace(ctx, bson.M{"_id": job.ID}, job).Err()
}
func (ms *mongoStorage) UpdateJob(job *jw.Job) error {
ctx, cancel := util.CtxWithTimeout(5 * time.Second)
defer cancel()

33
internal/storage/mongo/workflows.go

@ -69,7 +69,38 @@ func (ms *mongoStorage) Workflow(id string, mustExist bool) (*jw.Workflow, error
}
func (ms *mongoStorage) UpdateWorkflow(wf *jw.Workflow, job, nextJob *jw.Job) error {
return errors.NotImplemented()
ctx, cancel := util.CtxWithTimeout(5 * time.Second)
defer cancel()
session, err := ms.client.StartSession()
if err != nil {
return err
}
defer session.EndSession(ctx)
_, err = session.WithTransaction(
ctx,
func(ctx mongo.SessionContext) (interface{}, error) {
if err := ms.txUpdateJob(ctx, job); err != nil {
return nil, err
}
if wf != nil {
if err := ms.cWorkflows().FindOneAndReplace(ctx, bson.M{"_id": wf.ID}, wf).Err(); err != nil {
return nil, err
}
}
if nextJob == nil {
return nil, nil
}
return nil, ms.txInsertJob(ctx, nextJob)
},
)
return err
}
func (ms *mongoStorage) SetWorkflowPriority(id string, priority jw.Priority) error {

Loading…
Cancel
Save