add event base intelligency
This commit is contained in:
@@ -47,6 +47,10 @@ func (wf *Graph) IsProcessing(item GraphItem) bool {
|
||||
return item.Processing != nil
|
||||
}
|
||||
|
||||
func (wf *Graph) IsNativeTool(item GraphItem) bool {
|
||||
return item.NativeTool != nil
|
||||
}
|
||||
|
||||
func (wf *Graph) IsCompute(item GraphItem) bool {
|
||||
return item.Compute != nil
|
||||
}
|
||||
@@ -64,7 +68,7 @@ func (wf *Graph) IsWorkflow(item GraphItem) bool {
|
||||
}
|
||||
|
||||
func (g *Graph) GetAverageTimeRelatedToProcessingActivity(start time.Time, processings []*resources.ProcessingResource, resource resources.ResourceInterface,
|
||||
f func(GraphItem) resources.ResourceInterface, request *tools.APIRequest) (float64, float64) {
|
||||
f func(GraphItem) resources.ResourceInterface, instance int, bookingMode int, request *tools.APIRequest) (float64, float64, error) {
|
||||
nearestStart := float64(10000000000)
|
||||
oneIsInfinite := false
|
||||
longestDuration := float64(0)
|
||||
@@ -76,7 +80,10 @@ func (g *Graph) GetAverageTimeRelatedToProcessingActivity(start time.Time, proce
|
||||
} else if link.Source.ID == processing.GetID() && f(g.Items[link.Source.ID]) != nil && f(g.Items[link.Source.ID]).GetID() == resource.GetID() { // if the source is the processing and the destination is not a compute
|
||||
source = link.Destination.ID
|
||||
}
|
||||
priced := processing.ConvertToPricedResource(tools.PROCESSING_RESOURCE, request)
|
||||
priced, err := processing.ConvertToPricedResource(tools.PROCESSING_RESOURCE, &instance, &bookingMode, request)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
if source != "" {
|
||||
if priced.GetLocationStart() != nil {
|
||||
near := float64(priced.GetLocationStart().Sub(start).Seconds())
|
||||
@@ -97,15 +104,15 @@ func (g *Graph) GetAverageTimeRelatedToProcessingActivity(start time.Time, proce
|
||||
}
|
||||
}
|
||||
if oneIsInfinite {
|
||||
return nearestStart, -1
|
||||
return nearestStart, -1, nil
|
||||
}
|
||||
return nearestStart, longestDuration
|
||||
return nearestStart, longestDuration, nil
|
||||
}
|
||||
|
||||
/*
|
||||
* GetAverageTimeBeforeStart is a function that returns the average time before the start of a processing
|
||||
*/
|
||||
func (g *Graph) GetAverageTimeProcessingBeforeStart(average float64, processingID string, request *tools.APIRequest) float64 {
|
||||
func (g *Graph) GetAverageTimeProcessingBeforeStart(average float64, processingID string, instance int, bookingMode int, request *tools.APIRequest) (float64, error) {
|
||||
currents := []float64{} // list of current time
|
||||
for _, link := range g.Links { // for each link
|
||||
var source string // source is the source of the link
|
||||
@@ -121,13 +128,20 @@ func (g *Graph) GetAverageTimeProcessingBeforeStart(average float64, processingI
|
||||
if r == nil { // if item is nil, continue
|
||||
continue
|
||||
}
|
||||
priced := r.ConvertToPricedResource(dt, request)
|
||||
priced, err := r.ConvertToPricedResource(dt, &instance, &bookingMode, request)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
current := priced.GetExplicitDurationInS() // get the explicit duration of the item
|
||||
if current < 0 { // if current is negative, its means that duration of a before could be infinite continue
|
||||
return current
|
||||
return current, nil
|
||||
}
|
||||
current += g.GetAverageTimeProcessingBeforeStart(current, source, request) // get the average time before start of the source
|
||||
currents = append(currents, current) // append the current to the currents
|
||||
add, err := g.GetAverageTimeProcessingBeforeStart(current, source, instance, bookingMode, request)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
current += add // get the average time before start of the source
|
||||
currents = append(currents, current) // append the current to the currents
|
||||
}
|
||||
var max float64 // get the max time to wait dependancies to finish
|
||||
for _, current := range currents {
|
||||
@@ -135,12 +149,14 @@ func (g *Graph) GetAverageTimeProcessingBeforeStart(average float64, processingI
|
||||
max = current
|
||||
}
|
||||
}
|
||||
return max
|
||||
return max, nil
|
||||
}
|
||||
|
||||
func (g *Graph) GetResource(id string) (tools.DataType, resources.ResourceInterface) {
|
||||
if item, ok := g.Items[id]; ok {
|
||||
if item.Data != nil {
|
||||
return tools.NATIVE_TOOL, item.NativeTool
|
||||
} else if item.Data != nil {
|
||||
return tools.DATA_RESOURCE, item.Data
|
||||
} else if item.Compute != nil {
|
||||
return tools.COMPUTE_RESOURCE, item.Compute
|
||||
|
||||
Reference in New Issue
Block a user