jobqueue: add channel to workers

Stores the channel alongside the worker.
This commit is contained in:
Sanne Raymaekers 2024-04-19 11:52:21 +02:00
parent ede798ae6c
commit 1b4935c325
9 changed files with 46 additions and 26 deletions

View file

@ -823,8 +823,8 @@ func (s *Server) RequeueOrFinishJob(token uuid.UUID, maxRetries uint64, result j
return nil
}
func (s *Server) RegisterWorker(a string) (uuid.UUID, error) {
workerID, err := s.jobs.InsertWorker(a)
func (s *Server) RegisterWorker(c, a string) (uuid.UUID, error) {
workerID, err := s.jobs.InsertWorker(c, a)
if err != nil {
return uuid.Nil, err
}
@ -1059,7 +1059,18 @@ func (h *apiHandlers) PostWorkers(ctx echo.Context) error {
return err
}
workerID, err := h.server.RegisterWorker(body.Arch)
var channel string
if h.server.config.JWTEnabled {
tenant, err := auth.GetFromClaims(ctx.Request().Context(), h.server.config.TenantProviderFields)
if err != nil {
return api.HTTPErrorWithInternal(api.ErrorTenantNotFound, err)
}
// prefix the tenant to prevent collisions if support for specifying channels in a request is ever added
channel = "org-" + tenant
}
workerID, err := h.server.RegisterWorker(channel, body.Arch)
if err != nil {
return api.HTTPErrorWithInternal(api.ErrorInsertingWorker, err)
}