light modification
This commit is contained in:
@@ -13,11 +13,24 @@ import (
|
||||
|
||||
type workflowExecutionMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
shallow bool
|
||||
}
|
||||
|
||||
func newShallowAccessor(request *tools.APIRequest) *workflowExecutionMongoAccessor {
|
||||
return &workflowExecutionMongoAccessor{
|
||||
shallow: true,
|
||||
AbstractAccessor: utils.AbstractAccessor{
|
||||
Logger: logs.CreateLogger(tools.WORKFLOW_EXECUTION.String()), // Create a logger with the data type
|
||||
Request: request,
|
||||
Type: tools.WORKFLOW_EXECUTION,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func NewAccessor(request *tools.APIRequest) *workflowExecutionMongoAccessor {
|
||||
return &workflowExecutionMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
shallow: false,
|
||||
AbstractAccessor: utils.AbstractAccessor{
|
||||
Logger: logs.CreateLogger(tools.WORKFLOW_EXECUTION.String()), // Create a logger with the data type
|
||||
Request: request,
|
||||
Type: tools.WORKFLOW_EXECUTION,
|
||||
@@ -43,13 +56,13 @@ func (wfa *workflowExecutionMongoAccessor) CopyOne(data utils.DBObject) (utils.D
|
||||
|
||||
func (a *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericLoadOne[*WorkflowExecutions](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||
if d.(*WorkflowExecutions).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
|
||||
utils.GenericDeleteOne(d.GetID(), a)
|
||||
if d.(*WorkflowExecutions).State == enum.DRAFT && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
|
||||
utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request))
|
||||
return nil, 404, errors.New("not found")
|
||||
}
|
||||
if d.(*WorkflowExecutions).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
|
||||
if d.(*WorkflowExecutions).State == enum.SCHEDULED && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
|
||||
d.(*WorkflowExecutions).State = enum.FORGOTTEN
|
||||
utils.GenericRawUpdateOne(d, id, a)
|
||||
utils.GenericRawUpdateOne(d, id, newShallowAccessor(a.Request))
|
||||
}
|
||||
return d, 200, nil
|
||||
}, a)
|
||||
@@ -66,12 +79,13 @@ func (a *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search str
|
||||
func (a *workflowExecutionMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
|
||||
return func(d utils.DBObject) utils.ShallowDBObject {
|
||||
if d.(*WorkflowExecutions).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
|
||||
utils.GenericDeleteOne(d.GetID(), a)
|
||||
utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request))
|
||||
return nil
|
||||
}
|
||||
if d.(*WorkflowExecutions).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecutions).ExecDate) {
|
||||
d.(*WorkflowExecutions).State = enum.FORGOTTEN
|
||||
utils.GenericRawUpdateOne(d, d.GetID(), a)
|
||||
d, _, _ = utils.GenericRawUpdateOne(d, d.GetID(), newShallowAccessor(a.Request))
|
||||
return d
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
@@ -58,7 +58,6 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest)
|
||||
}
|
||||
wf := res.(*workflow.Workflow)
|
||||
longest, priceds, wf, err := wf.Planify(ws.Start, ws.End, request)
|
||||
fmt.Println("longest", longest, err)
|
||||
if err != nil {
|
||||
return false, wf, []*WorkflowExecutions{}, err
|
||||
}
|
||||
@@ -68,7 +67,6 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest)
|
||||
ws.Warning = "The workflow may be too long to be executed in the given time frame, we will try to book it anyway\n"
|
||||
}
|
||||
execs, err := ws.getExecutions(wf)
|
||||
fmt.Println("execs", execs, err)
|
||||
if err != nil {
|
||||
return false, wf, []*WorkflowExecutions{}, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user