booking start intelligency
This commit is contained in:
@@ -4,9 +4,12 @@ import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type AbstractWorkflow struct {
|
||||
@@ -16,11 +19,14 @@ type AbstractWorkflow struct {
|
||||
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"`
|
||||
}
|
||||
|
||||
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) bool {
|
||||
if slices.Contains(w.Datacenters, link.Destination.ID) || slices.Contains(w.Datacenters, link.Source.ID) {
|
||||
return true
|
||||
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) (bool, string) {
|
||||
if slices.Contains(w.Datacenters, link.Source.ID) {
|
||||
return true, link.Source.ID
|
||||
}
|
||||
return false
|
||||
if slices.Contains(w.Datacenters, link.Destination.ID) {
|
||||
return true, link.Destination.ID
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
|
||||
type Workflow struct {
|
||||
@@ -28,35 +34,34 @@ type Workflow struct {
|
||||
AbstractWorkflow
|
||||
}
|
||||
|
||||
func (d *Workflow) GetName() string {
|
||||
return d.Name
|
||||
func (wfa *Workflow) CheckBooking() (bool, error) {
|
||||
// check if
|
||||
if wfa.Schedule == nil || wfa.Schedule.Start == nil {
|
||||
return false, nil
|
||||
}
|
||||
if wfa.Schedule.End == nil {
|
||||
// if no end... then Book like a savage
|
||||
return true, nil
|
||||
}
|
||||
e := *wfa.Schedule.End
|
||||
accessor := wfa.GetAccessor()
|
||||
res, code, err := accessor.Search(&dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"workflowexecution.state": {{Operator: dbs.EQUAL.String(), Value: workflow_execution.SCHEDULED.EnumIndex()}},
|
||||
"workflowexecution.execution_date": {
|
||||
{Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(e)},
|
||||
{Operator: dbs.GTE.String(), Value: primitive.NewDateTimeFromTime(*wfa.Schedule.Start)},
|
||||
},
|
||||
},
|
||||
}, "")
|
||||
if code != 200 {
|
||||
return false, err
|
||||
}
|
||||
return len(res) == 0, nil
|
||||
}
|
||||
|
||||
func (d *Workflow) CheckBooking() bool {
|
||||
return true
|
||||
/*if d.Schedule != nil && d.Schedule.Start != nil {
|
||||
sd := primitive.NewDateTimeFromTime(d.Schedule.Start.Add(time.Minute * -1))
|
||||
var f dbs.Filters
|
||||
if d.Schedule.End == nil {
|
||||
ed := primitive.NewDateTimeFromTime(d.Schedule.Start.Add(time.Minute * 10))
|
||||
f = dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"execution_date": {{Operator: "gte", Value: sd}, {Operator: "lte", Value: ed}},
|
||||
},
|
||||
}
|
||||
} else {
|
||||
ed := primitive.NewDateTimeFromTime(d.Schedule.End.Add(time.Minute * 1))
|
||||
f = dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"execution_date": {{Operator: "gte", Value: sd}},
|
||||
"end_date": {{Operator: "lte", Value: ed}},
|
||||
},
|
||||
}
|
||||
}
|
||||
res, _, _ := (&workflow_execution.WorkflowExecution{}).GetAccessor().Search(&f, "")
|
||||
return len(res) == 0
|
||||
}
|
||||
return true*/
|
||||
func (d *Workflow) GetName() string {
|
||||
return d.Name
|
||||
}
|
||||
|
||||
func (d *Workflow) GetAccessor() utils.Accessor {
|
||||
|
||||
Reference in New Issue
Block a user