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
*/
type WorkflowExecution struct {
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
ExecutionsID string `json:"executions_id,omitempty" bson:"executions_id,omitempty"`
ExecDate time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` // ExecDate is the execution date of the workflow, is required
EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` // EndDate is the end date 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
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
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
ExecutionsID string `json:"executions_id,omitempty" bson:"executions_id,omitempty"`
ExecDate time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` // ExecDate is the execution date of the workflow, is required
EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` // EndDate is the end date 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() {
@ -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 {
items := []*booking.Booking{}
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
if s := priced.GetLocationStart(); s != nil {
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)
bookingItem := &booking.Booking{
AbstractObject: utils.AbstractObject{
UUID: uuid.New().String(),
Name: d.GetName() + "_" + executionsID + "_" + wfID,
},
ExecutionsID: executionsID,
@ -137,6 +148,8 @@ func (d *WorkflowExecution) bookEach(executionsID string, wfID string, dt tools.
ExpectedEndDate: &end,
}
items = append(items, bookingItem)
d.PeerBookByResource[priced.GetCreatorID()][priced.GetID()] = append(
d.PeerBookByResource[priced.GetCreatorID()][priced.GetID()], bookingItem.GetID())
}
return items
}

View File

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