moved the code that execute the booking into a separated function so that it can be launched as goroutine and parallelize get booking$
This commit is contained in:
parent
58dc579255
commit
1ade41aeae
@ -15,6 +15,7 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/robfig/cron"
|
"github.com/robfig/cron"
|
||||||
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -83,24 +84,39 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest)
|
|||||||
l.Debug().Msg("looping throughs execs : " + string(i))
|
l.Debug().Msg("looping throughs execs : " + string(i))
|
||||||
bookings = append(bookings, exec.Book(ws.UUID, wfID, priceds)...)
|
bookings = append(bookings, exec.Book(ws.UUID, wfID, priceds)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errCh := make(chan error, len(bookings))
|
||||||
|
|
||||||
for _, b := range bookings {
|
for _, b := range bookings {
|
||||||
bl := l.With().Str("booking",b.UUID).Logger()
|
go getBooking(l, b, request, wf, execs, bookings, errCh)
|
||||||
meth := request.Caller.URLS[tools.BOOKING][tools.GET]
|
}
|
||||||
meth = strings.ReplaceAll(meth, ":id", b.ResourceID)
|
|
||||||
meth = strings.ReplaceAll(meth, ":start_date", b.ExpectedStartDate.Format("2006-01-02T15:04:05"))
|
for err := range(errCh){
|
||||||
meth = strings.ReplaceAll(meth, ":end_date", b.ExpectedEndDate.Format("2006-01-02T15:04:05"))
|
|
||||||
request.Caller.URLS[tools.BOOKING][tools.GET] = meth
|
|
||||||
bl.Debug().Msg("Get booking on" + b.DestPeerID)
|
|
||||||
_, err := (&peer.Peer{}).LaunchPeerExecution(b.DestPeerID, b.ResourceID, tools.BOOKING, tools.GET, nil, request.Caller)
|
|
||||||
bl.Debug().Msg("Received response from Get booking on " + b.DestPeerID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, wf, execs, bookings, err
|
return false, wf, execs, bookings, err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, wf, execs, bookings, nil
|
return true, wf, execs, bookings, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBooking(l zerolog.Logger, b *booking.Booking, request *tools.APIRequest, wf *workflow.Workflow, execs []*WorkflowExecution, bookings []*booking.Booking, errCh chan error) {
|
||||||
|
bl := l.With().Str("booking", b.UUID).Logger()
|
||||||
|
meth := request.Caller.URLS[tools.BOOKING][tools.GET]
|
||||||
|
meth = strings.ReplaceAll(meth, ":id", b.ResourceID)
|
||||||
|
meth = strings.ReplaceAll(meth, ":start_date", b.ExpectedStartDate.Format("2006-01-02T15:04:05"))
|
||||||
|
meth = strings.ReplaceAll(meth, ":end_date", b.ExpectedEndDate.Format("2006-01-02T15:04:05"))
|
||||||
|
request.Caller.URLS[tools.BOOKING][tools.GET] = meth
|
||||||
|
bl.Debug().Msg("Get booking " + b.UUID + "on" + b.DestPeerID)
|
||||||
|
_, err := (&peer.Peer{}).LaunchPeerExecution(b.DestPeerID, b.ResourceID, tools.BOOKING, tools.GET, nil, request.Caller)
|
||||||
|
bl.Debug().Msg("Received response from Get booking on " + b.DestPeerID)
|
||||||
|
if err != nil {
|
||||||
|
errCh <- err
|
||||||
|
}
|
||||||
|
|
||||||
|
errCh <- nil
|
||||||
|
}
|
||||||
|
|
||||||
func (ws *WorkflowSchedule) Schedules(wfID string, request *tools.APIRequest) (*WorkflowSchedule, *workflow.Workflow, []*WorkflowExecution, error) {
|
func (ws *WorkflowSchedule) Schedules(wfID string, request *tools.APIRequest) (*WorkflowSchedule, *workflow.Workflow, []*WorkflowExecution, error) {
|
||||||
if request == nil {
|
if request == nil {
|
||||||
return ws, nil, []*WorkflowExecution{}, errors.New("no request found")
|
return ws, nil, []*WorkflowExecution{}, errors.New("no request found")
|
||||||
|
Loading…
Reference in New Issue
Block a user