add sets up

This commit is contained in:
mr
2025-06-20 12:10:36 +02:00
parent 583ca2fbac
commit 29b192211d
22 changed files with 136 additions and 131 deletions

View File

@@ -37,8 +37,6 @@ type WorkflowSchedule struct {
DurationS float64 `json:"duration_s" default:"-1"` // End is the end time of the schedule
Cron string `json:"cron,omitempty"` // here the cron format : ss mm hh dd MM dw task
SelectedBuyingStrategy pricing.BuyingStrategy `json:"selected_buying_strategy"`
SelectedPricingStrategy int `json:"selected_pricing_strategy"`
SelectedBillingStrategy pricing.BillingStrategy `json:"selected_billing_strategy"`
}
@@ -70,7 +68,7 @@ func (ws *WorkflowSchedule) GetBuyAndBook(wfID string, request *tools.APIRequest
return false, nil, []*WorkflowExecution{}, []*purchase_resource.PurchaseResource{}, []*booking.Booking{}, errors.New("could not load the workflow with id: " + err.Error())
}
wf := res.(*workflow.Workflow)
longest, priceds, wf, err := wf.Planify(ws.Start, ws.End, request, int(ws.SelectedBuyingStrategy), ws.SelectedPricingStrategy)
longest, priceds, wf, err := wf.Planify(ws.Start, ws.End, request)
if err != nil {
return false, wf, []*WorkflowExecution{}, []*purchase_resource.PurchaseResource{}, []*booking.Booking{}, err
}
@@ -90,10 +88,6 @@ func (ws *WorkflowSchedule) GetBuyAndBook(wfID string, request *tools.APIRequest
bookings = append(bookings, exec.Book(ws.UUID, wfID, priceds)...)
}
if err := ws.GenerateOrder(purchased, bookings, request); err != nil {
return false, wf, execs, purchased, bookings, err
}
errCh := make(chan error, len(bookings))
var m sync.Mutex
@@ -107,6 +101,10 @@ func (ws *WorkflowSchedule) GetBuyAndBook(wfID string, request *tools.APIRequest
}
}
if err := ws.GenerateOrder(purchased, bookings, request); err != nil {
return false, wf, execs, purchased, bookings, err
}
return true, wf, execs, purchased, bookings, nil
}
@@ -122,7 +120,7 @@ func (ws *WorkflowSchedule) GenerateOrder(purchases []*purchase_resource.Purchas
Status: enum.PENDING,
}
if res, _, err := order.NewAccessor(request).StoreOne(newOrder); err == nil {
if _, err := bill.DraftBill(res.(*order.Order), request); err != nil {
if _, err := bill.DraftFirstBill(res.(*order.Order), request); err != nil {
return err
}
return nil