Create a new runner async after one gets claimed
This commit is contained in:
@ -234,10 +234,12 @@ func (n *NomadEnvironment) UpdateRunnerSpecs(apiClient nomad.ExecutorAPI) error
|
||||
func (n *NomadEnvironment) Sample(apiClient nomad.ExecutorAPI) (runner.Runner, bool) {
|
||||
r, ok := n.idleRunners.Sample()
|
||||
if ok {
|
||||
err := n.createRunner(apiClient)
|
||||
if err != nil {
|
||||
log.WithError(err).WithField("environmentID", n.ID()).Error("Couldn't create new runner for claimed one")
|
||||
}
|
||||
go func() {
|
||||
err := n.createRunner(apiClient)
|
||||
if err != nil {
|
||||
log.WithError(err).WithField("environmentID", n.ID()).Error("Couldn't create new runner for claimed one")
|
||||
}
|
||||
}()
|
||||
}
|
||||
return r, ok
|
||||
}
|
||||
|
@ -141,15 +141,18 @@ func (m *NomadRunnerManager) Claim(environmentID dto.EnvironmentID, duration int
|
||||
if !ok {
|
||||
return nil, ErrUnknownExecutionEnvironment
|
||||
}
|
||||
log.Debug("Before Sample")
|
||||
runner, ok := environment.Sample(m.apiClient)
|
||||
if !ok {
|
||||
return nil, ErrNoRunnersAvailable
|
||||
}
|
||||
m.usedRunners.Add(runner)
|
||||
log.Debug("Before Mark Runner As Used")
|
||||
err := m.apiClient.MarkRunnerAsUsed(runner.ID(), duration)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't mark runner as used: %w", err)
|
||||
}
|
||||
log.Debug("After Mark Runner As Used")
|
||||
|
||||
runner.SetupTimeout(time.Duration(duration) * time.Second)
|
||||
return runner, nil
|
||||
|
Reference in New Issue
Block a user