Booking check and booking post have been transformed in goroutine to improve performance when booking several execution with cron expressions
This commit is contained in:
parent
cd7ae788b1
commit
da0de80afd
@ -7,7 +7,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
@ -55,8 +54,6 @@ func NewScheduler(start string, end string, durationInS float64, cron string) *W
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest) (bool, *workflow.Workflow, []*WorkflowExecution, []*booking.Booking, error) {
|
func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest) (bool, *workflow.Workflow, []*WorkflowExecution, []*booking.Booking, error) {
|
||||||
l := logs.GetLogger().With().Str("SchedulerID", ws.UUID).Logger()
|
|
||||||
l.Debug().Msg("Checking booking")
|
|
||||||
if request.Caller == nil && request.Caller.URLS == nil && request.Caller.URLS[tools.BOOKING] == nil || request.Caller.URLS[tools.BOOKING][tools.GET] == "" {
|
if request.Caller == nil && request.Caller.URLS == nil && request.Caller.URLS[tools.BOOKING] == nil || request.Caller.URLS[tools.BOOKING][tools.GET] == "" {
|
||||||
return false, nil, []*WorkflowExecution{}, []*booking.Booking{}, errors.New("no caller defined")
|
return false, nil, []*WorkflowExecution{}, []*booking.Booking{}, errors.New("no caller defined")
|
||||||
}
|
}
|
||||||
@ -75,14 +72,12 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest)
|
|||||||
if ws.End != nil && ws.Start.Add(time.Duration(longest)*time.Second).After(*ws.End) {
|
if ws.End != nil && ws.Start.Add(time.Duration(longest)*time.Second).After(*ws.End) {
|
||||||
ws.Warning = "The workflow may be too long to be executed in the given time frame, we will try to book it anyway\n"
|
ws.Warning = "The workflow may be too long to be executed in the given time frame, we will try to book it anyway\n"
|
||||||
}
|
}
|
||||||
l.Debug().Msg("Getting executions")
|
|
||||||
execs, err := ws.getExecutions(wf)
|
execs, err := ws.getExecutions(wf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, wf, []*WorkflowExecution{}, []*booking.Booking{}, err
|
return false, wf, []*WorkflowExecution{}, []*booking.Booking{}, err
|
||||||
}
|
}
|
||||||
bookings := []*booking.Booking{}
|
bookings := []*booking.Booking{}
|
||||||
for i, exec := range execs {
|
for _, exec := range execs {
|
||||||
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)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,15 +107,13 @@ func getBooking(l zerolog.Logger, b *booking.Booking, request *tools.APIRequest,
|
|||||||
}
|
}
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
|
|
||||||
bl := l.With().Str("booking", b.UUID).Logger()
|
|
||||||
meth := request.Caller.URLS[tools.BOOKING][tools.GET]
|
meth := request.Caller.URLS[tools.BOOKING][tools.GET]
|
||||||
meth = strings.ReplaceAll(meth, ":id", b.ResourceID)
|
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, ":start_date", b.ExpectedStartDate.Format("2006-01-02T15:04:05"))
|
||||||
meth = strings.ReplaceAll(meth, ":end_date", b.ExpectedEndDate.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
|
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, &c)
|
_, err = (&peer.Peer{}).LaunchPeerExecution(b.DestPeerID, b.ResourceID, tools.BOOKING, tools.GET, nil, &c)
|
||||||
bl.Debug().Msg("Received response from Get booking " + b.UUID + " on " + b.DestPeerID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errCh <- err
|
errCh <- err
|
||||||
return
|
return
|
||||||
@ -195,11 +188,8 @@ func (ws *WorkflowSchedule) BookExecs(booking *booking.Booking, request *tools.A
|
|||||||
}
|
}
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
|
|
||||||
l := logs.GetLogger().With().Str("SchedulerID", ws.UUID).Logger()
|
|
||||||
l.Debug().Msg("Booking " + booking.UUID + " on " + booking.DestPeerID)
|
|
||||||
_, err = (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
|
_, err = (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
|
||||||
tools.BOOKING, tools.POST, booking.Serialize(booking), &c)
|
tools.BOOKING, tools.POST, booking.Serialize(booking), &c)
|
||||||
l.Debug().Msg("Received answer for booking " + booking.UUID + " on " + booking.DestPeerID)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errCh <- err
|
errCh <- err
|
||||||
|
Loading…
Reference in New Issue
Block a user