Manager: run some worker management API calls in a background context
Run the actually-doing-stuff parts of `RequestWorkerStatusChange()` and `SetWorkerTags()` in a background context. That way the operation can continue even when the HTTP client disconnects.
This commit is contained in:
parent
6c2d3d7fc0
commit
d60451a829
@ -179,6 +179,11 @@ func (f *Flamenco) RequestWorkerStatusChange(e echo.Context, workerUUID string)
|
|||||||
|
|
||||||
logger.Info().Msg("worker status change requested")
|
logger.Info().Msg("worker status change requested")
|
||||||
|
|
||||||
|
// All information to do the operation is known, so even when the client
|
||||||
|
// disconnects, the work should be completed.
|
||||||
|
ctx, ctxCancel := bgContext()
|
||||||
|
defer ctxCancel()
|
||||||
|
|
||||||
if dbWorker.Status == change.Status {
|
if dbWorker.Status == change.Status {
|
||||||
// Requesting that the worker should go to its current status basically
|
// Requesting that the worker should go to its current status basically
|
||||||
// means cancelling any previous status change request.
|
// means cancelling any previous status change request.
|
||||||
@ -188,7 +193,7 @@ func (f *Flamenco) RequestWorkerStatusChange(e echo.Context, workerUUID string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store the status change.
|
// Store the status change.
|
||||||
if err := f.persist.SaveWorker(e.Request().Context(), dbWorker); err != nil {
|
if err := f.persist.SaveWorker(ctx, dbWorker); err != nil {
|
||||||
logger.Error().Err(err).Msg("saving worker after status change request")
|
logger.Error().Err(err).Msg("saving worker after status change request")
|
||||||
return sendAPIError(e, http.StatusInternalServerError, "error saving worker: %v", err)
|
return sendAPIError(e, http.StatusInternalServerError, "error saving worker: %v", err)
|
||||||
}
|
}
|
||||||
@ -232,6 +237,11 @@ func (f *Flamenco) SetWorkerTags(e echo.Context, workerUUID string) error {
|
|||||||
Logger()
|
Logger()
|
||||||
logger.Info().Msg("worker tag change requested")
|
logger.Info().Msg("worker tag change requested")
|
||||||
|
|
||||||
|
// All information to do the operation is known, so even when the client
|
||||||
|
// disconnects, the work should be completed.
|
||||||
|
ctx, ctxCancel := bgContext()
|
||||||
|
defer ctxCancel()
|
||||||
|
|
||||||
// Store the new tag assignment.
|
// Store the new tag assignment.
|
||||||
if err := f.persist.WorkerSetTags(ctx, dbWorker, change.TagIds); err != nil {
|
if err := f.persist.WorkerSetTags(ctx, dbWorker, change.TagIds); err != nil {
|
||||||
logger.Error().Err(err).Msg("saving worker after tag change request")
|
logger.Error().Err(err).Msg("saving worker after tag change request")
|
||||||
|
Loading…
Reference in New Issue
Block a user