Skip to content

Commit 152dda5

Browse files
authored
feat(api): compare hatchery and job region for register (#6156)
1 parent 97a158c commit 152dda5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

engine/api/worker/registration.go

+9
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ func RegisterWorker(ctx context.Context, db gorpmapper.SqlExecutorWithTx, store
110110
return nil, sdk.WrapError(sdk.ErrForbidden, "hatchery can't register job (id: %q) with model (path: %q) for a group that is not in job's exec groups", spawnArgs.JobID, model.Path())
111111
}
112112
}
113+
114+
// Check additional information based on the consumer if a region is set, allows to register only job with same region.
115+
// TODO add another information on the consumer to allow job with a specific region requirement or no region (runNodeJob.Region == nil).
116+
if hatcheryConsumer.ServiceRegion != nil && *hatcheryConsumer.ServiceRegion != "" {
117+
canTakeJobWithRegion := runNodeJob.Region != nil && *runNodeJob.Region == *hatcheryConsumer.ServiceRegion
118+
if !canTakeJobWithRegion {
119+
return nil, sdk.WrapError(sdk.ErrForbidden, "hatchery can't register job with id %q for region %s", spawnArgs.JobID, *runNodeJob.Region)
120+
}
121+
}
113122
}
114123

115124
// Instanciate a new worker

0 commit comments

Comments
 (0)