Skip to content

Commit

Permalink
Merge pull request #31 from nextmv-io/feature/eng-5070-parallel-solve…
Browse files Browse the repository at this point in the history
…r-cycle-invocation-do-not-comply-with-max

Feature/eng 5070 parallel solver cycle invocation do not comply with max
  • Loading branch information
davidrijsman authored Apr 26, 2024
2 parents 980b2b5 + c2f0d11 commit bf0a238
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 10 additions & 3 deletions solve_solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

"github.com/nextmv-io/nextroute/common"
"github.com/nextmv-io/sdk/run"
)

// IntParameterOptions are the options for an integer parameter.
Expand Down Expand Up @@ -247,7 +246,12 @@ func (s *solveImpl) Solve(
s.workSolution = newWorkSolution
s.random = rand.New(rand.NewSource(newWorkSolution.Random().Int63()))

start := ctx.Value(run.Start).(time.Time)
start := time.Now()

ctx, cancel := context.WithDeadline(
ctx,
start.Add(solveOptions.Duration),
)

solveInformation := &solveInformationImpl{
iteration: 0,
Expand All @@ -268,7 +272,10 @@ func (s *solveImpl) Solve(
Error: nil,
}
go func() {
defer close(solutions)
defer func() {
close(solutions)
cancel()
}()

Loop:
for iteration := 0; iteration < solveOptions.Iterations; iteration++ {
Expand Down
6 changes: 5 additions & 1 deletion solve_solver_parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ func (s *parallelSolverImpl) Solve(
}
}

start := ctx.Value(run.Start).(time.Time)
start := time.Now()

if ctx.Value(run.Start) != nil {
start = ctx.Value(run.Start).(time.Time)
}

ctx, cancel := context.WithDeadline(
ctx,
Expand Down
2 changes: 2 additions & 0 deletions tests/custom_operators/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"context"
"log"
"time"

"github.com/nextmv-io/nextroute"
"github.com/nextmv-io/nextroute/check"
Expand Down Expand Up @@ -76,6 +77,7 @@ func solver(
) (nextroute.SolveOptions, error) {
return nextroute.SolveOptions{
Iterations: 1000,
Duration: 10 * time.Minute,
}, nil
},
)
Expand Down

0 comments on commit bf0a238

Please sign in to comment.