Skip to content

Commit 4285535

Browse files
authored
fix(hatchery): check canSpawn (#5174)
even if it's for a worker model registration Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
1 parent 7f83084 commit 4285535

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

sdk/hatchery/register.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ loopModels:
3434
if models[k].Type != h.ModelType() {
3535
continue
3636
}
37-
if h.NeedRegistration(ctx, &models[k]) || models[k].CheckRegistration {
37+
if h.CanSpawn(ctx, &models[k], 0, nil) && (h.NeedRegistration(ctx, &models[k]) || models[k].CheckRegistration) {
3838
log.Debug("hatchery> workerRegister> need register")
3939
} else {
4040
continue
@@ -68,15 +68,13 @@ loopModels:
6868
continue
6969
}
7070

71-
if h.NeedRegistration(ctx, &models[k]) || models[k].CheckRegistration {
72-
if err := h.CDSClient().WorkerModelBook(models[k].Group.Name, models[k].Name); err != nil {
73-
log.Debug("%v", sdk.WrapError(err, "cannot book model %s with id %d", models[k].Name, models[k].ID))
74-
} else {
75-
log.Info(ctx, "hatchery> workerRegister> spawning model %s (%d)", models[k].Name, models[k].ID)
76-
//Ask for the creation
77-
startWorkerChan <- workerStarterRequest{
78-
registerWorkerModel: &models[k],
79-
}
71+
if err := h.CDSClient().WorkerModelBook(models[k].Group.Name, models[k].Name); err != nil {
72+
log.Debug("%v", sdk.WrapError(err, "cannot book model %s with id %d", models[k].Name, models[k].ID))
73+
} else {
74+
log.Info(ctx, "hatchery> workerRegister> spawning model %s (%d)", models[k].Name, models[k].ID)
75+
//Ask for the creation
76+
startWorkerChan <- workerStarterRequest{
77+
registerWorkerModel: &models[k],
8078
}
8179
}
8280
}

0 commit comments

Comments
 (0)