workflow scheduler create booking with a booking execution lot id

This commit is contained in:
mr 2025-02-12 15:45:03 +01:00
parent c0e6247fb8
commit 576f53f81b
2 changed files with 20 additions and 6 deletions

View File

@ -20,12 +20,13 @@ import (
* workflows generate their own executions * workflows generate their own executions
*/ */
type WorkflowExecution struct { type WorkflowExecution struct {
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name) utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
ExecutionsID string `json:"executions_id,omitempty" bson:"executions_id,omitempty"` PeerBookByResource map[string]map[string][]string `json:"peer_book_by_resource,omitempty" bson:"peer_book_by_resource,omitempty"` // BookByResource is a map of the resource id and the list of the booking id
ExecDate time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` // ExecDate is the execution date of the workflow, is required ExecutionsID string `json:"executions_id,omitempty" bson:"executions_id,omitempty"`
EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` // EndDate is the end date of the workflow ExecDate time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` // ExecDate is the execution date of the workflow, is required
State enum.BookingStatus `json:"state" bson:"state" default:"0"` // TEMPORARY TODO DEFAULT 1 -> 0 State is the state of the workflow EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` // EndDate is the end date of the workflow
WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow State enum.BookingStatus `json:"state" bson:"state" default:"0"` // TEMPORARY TODO DEFAULT 1 -> 0 State is the state of the workflow
WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
} }
func (r *WorkflowExecution) StoreDraftDefault() { func (r *WorkflowExecution) StoreDraftDefault() {
@ -117,6 +118,15 @@ func (d *WorkflowExecution) Book(executionsID string, wfID string, priceds map[t
func (d *WorkflowExecution) bookEach(executionsID string, wfID string, dt tools.DataType, priceds []pricing.PricedItemITF) []*booking.Booking { func (d *WorkflowExecution) bookEach(executionsID string, wfID string, dt tools.DataType, priceds []pricing.PricedItemITF) []*booking.Booking {
items := []*booking.Booking{} items := []*booking.Booking{}
for _, priced := range priceds { for _, priced := range priceds {
if d.PeerBookByResource == nil {
d.PeerBookByResource = map[string]map[string][]string{}
}
if d.PeerBookByResource[priced.GetCreatorID()] == nil {
d.PeerBookByResource[priced.GetCreatorID()] = map[string][]string{}
}
if d.PeerBookByResource[priced.GetCreatorID()][priced.GetID()] == nil {
d.PeerBookByResource[priced.GetCreatorID()][priced.GetID()] = []string{}
}
start := d.ExecDate start := d.ExecDate
if s := priced.GetLocationStart(); s != nil { if s := priced.GetLocationStart(); s != nil {
start = *s start = *s
@ -124,6 +134,7 @@ func (d *WorkflowExecution) bookEach(executionsID string, wfID string, dt tools.
end := start.Add(time.Duration(priced.GetExplicitDurationInS()) * time.Second) end := start.Add(time.Duration(priced.GetExplicitDurationInS()) * time.Second)
bookingItem := &booking.Booking{ bookingItem := &booking.Booking{
AbstractObject: utils.AbstractObject{ AbstractObject: utils.AbstractObject{
UUID: uuid.New().String(),
Name: d.GetName() + "_" + executionsID + "_" + wfID, Name: d.GetName() + "_" + executionsID + "_" + wfID,
}, },
ExecutionsID: executionsID, ExecutionsID: executionsID,
@ -137,6 +148,8 @@ func (d *WorkflowExecution) bookEach(executionsID string, wfID string, dt tools.
ExpectedEndDate: &end, ExpectedEndDate: &end,
} }
items = append(items, bookingItem) items = append(items, bookingItem)
d.PeerBookByResource[priced.GetCreatorID()][priced.GetID()] = append(
d.PeerBookByResource[priced.GetCreatorID()][priced.GetID()], bookingItem.GetID())
} }
return items return items
} }

View File

@ -88,6 +88,7 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest)
return false, wf, execs, bookings, err return false, wf, execs, bookings, err
} }
} }
} }
return true, wf, execs, bookings, nil return true, wf, execs, bookings, nil
} }