oc-lib/models/workflow/workflow.go

85 lines
2.0 KiB
Go
Raw Normal View History

2024-07-19 10:54:58 +02:00
package oclib
import (
"encoding/json"
2024-07-26 10:36:23 +02:00
"slices"
2024-07-19 10:54:58 +02:00
2024-07-26 10:36:23 +02:00
"cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
2024-07-19 10:54:58 +02:00
"cloud.o-forge.io/core/oc-lib/models/utils"
)
2024-07-26 10:36:23 +02:00
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
}
2024-07-19 10:54:58 +02:00
type Workflow struct {
2024-07-19 13:15:51 +02:00
utils.AbstractObject
2024-07-26 10:36:23 +02:00
AbstractWorkflow
2024-07-19 10:54:58 +02:00
}
func (d *Workflow) GetName() string {
return d.Name
}
2024-08-08 15:56:48 +02:00
func (d *Workflow) CheckBooking() bool {
2024-08-12 09:30:07 +02:00
return true
/*if d.Schedule != nil && d.Schedule.Start != nil {
2024-08-08 16:26:19 +02:00
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}},
},
}
2024-08-08 15:56:48 +02:00
}
2024-08-08 17:00:44 +02:00
res, _, _ := (&workflow_execution.WorkflowExecution{}).GetAccessor().Search(&f, "")
2024-08-08 15:56:48 +02:00
return len(res) == 0
}
2024-08-12 09:30:07 +02:00
return true*/
2024-08-08 15:56:48 +02:00
}
2024-07-19 10:54:58 +02:00
func (d *Workflow) GetAccessor() utils.Accessor {
2024-07-31 10:07:55 +02:00
data := New()
2024-07-19 10:54:58 +02:00
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
}
2024-07-24 09:53:30 +02:00
json.Unmarshal(b, &m)
2024-07-19 10:54:58 +02:00
return m
}