Avoid error when fetching task that was assigned to soft-deleted worker

When a Worker is soft-deleted, references to it are not cleaned up by
the database (that only happens when it is really deleted). As a result,
the "last-assigned worker of a task" field is still set, but the worker
itself cannot be fetched any more.

This is just a quick fix to avoid an error. It's probably better to
remove the soft-deletion of Workers, as the feature is not really used
anyway. Or to implement it properly, so that the info is used.
This commit is contained in:
Sybren A. Stüvel 2025-05-26 17:57:48 +02:00
parent 55491675e2
commit 3541575a75

View File

@ -143,12 +143,17 @@ func (f *Flamenco) FetchTask(e echo.Context, taskID string) error {
// worker's UUID and let the caller fetch the worker info themselves if
// necessary.
taskWorker, err := f.persist.FetchWorker(ctx, taskJobWorker.WorkerUUID)
if err != nil {
logger.Warn().Err(err).Msg("error fetching task worker")
switch {
case errors.Is(err, persistence.ErrWorkerNotFound):
// This is fine, workers can be soft-deleted from the database, and then
// the above FetchWorker call will not return it.
case err != nil:
logger.Warn().Err(err).Str("worker", taskJobWorker.WorkerUUID).Msg("error fetching task worker")
return sendAPIError(e, http.StatusInternalServerError, "error fetching task worker")
}
default:
apiTask.Worker = workerToTaskWorker(taskWorker)
}
}
// Fetch & convert the failure list.
failedWorkers, err := f.persist.FetchTaskFailureList(ctx, &taskJobWorker.Task)