package oclib import ( "encoding/json" "fmt" "slices" "time" "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" "go.mongodb.org/mongo-driver/bson/primitive" ) type AbstractWorkflow struct { resources.ResourceSet Graph *graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"` Schedule *WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,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 } return false } type Workflow struct { utils.AbstractObject AbstractWorkflow } func (d *Workflow) GetName() string { return d.Name } func (d *Workflow) CheckBooking() bool { fmt.Println("CheckBooking", d.Schedule) 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, code, err := d.GetAccessor().Search(&f, "") fmt.Println("res", res, f, code, err) return len(res) == 0 } return true } func (d *Workflow) GetAccessor() utils.Accessor { data := New() data.SetLogger(utils.WORKFLOW) return data } func (dma *Workflow) Deserialize(j map[string]interface{}) utils.DBObject { b, err := json.Marshal(j) if err != nil { return nil } json.Unmarshal(b, dma) return dma } func (dma *Workflow) Serialize() map[string]interface{} { var m map[string]interface{} b, err := json.Marshal(dma) if err != nil { return nil } json.Unmarshal(b, &m) return m }