Transcode Task Handling

This commit is contained in:
Samuel Lorch 2024-06-22 21:12:52 +02:00
parent fea955fb79
commit 13ea1cb755
6 changed files with 164 additions and 20 deletions

View file

@ -233,23 +233,36 @@ func updateWorkerTaskStatus(ctx context.Context) {
return
}
if ts.Task.Type == constants.TASK_TYPE_HEALTHCHECK && (ts.Task.Status == constants.TASK_STATUS_FAILED || ts.Task.Status == constants.TASK_STATUS_SUCCESS) {
var health constants.FileHealth
if ts.Task.Status == constants.TASK_STATUS_SUCCESS {
health = constants.FILE_HEALTH_HEALTHY
} else {
// TODO, not all failures mean the file is damaged, only update on success and track ffmpeg errors in task result data. also remove -xerror and scan for errors manually to see all problems in logs
health = constants.FILE_HEALTH_DAMAGED
}
_, err = db.Exec(ctx, "UPDATE files SET health = $2 WHERE id = $1", ts.Task.FileID, health)
if err != nil {
slog.ErrorContext(ctx, "Updating File health", "err", err)
return
}
}
// Tell Worker to Delete Finished Tasks
if ts.Task.Status == constants.TASK_STATUS_FAILED || ts.Task.Status == constants.TASK_STATUS_SUCCESS {
if ts.Task.Type == constants.TASK_TYPE_HEALTHCHECK {
var health constants.FileHealth
if ts.Task.Status == constants.TASK_STATUS_SUCCESS {
health = constants.FILE_HEALTH_HEALTHY
// TODO Auto Queue Transcode for Successfull Transcodes if library setting
} else {
// TODO, not all failures mean the file is damaged, only update on success and track ffmpeg errors in task result data. also remove -xerror and scan for errors manually to see all problems in logs
health = constants.FILE_HEALTH_DAMAGED
}
_, err = db.Exec(ctx, "UPDATE files SET health = $2 WHERE id = $1", ts.Task.FileID, health)
if err != nil {
slog.ErrorContext(ctx, "Updating File health", "err", err)
return
}
} else if ts.Task.Type == constants.TASK_TYPE_TRANSCODE {
var transcode constants.FileTranscode
if ts.Task.Status == constants.TASK_STATUS_SUCCESS {
transcode = constants.FILE_TRANSCODE_SUCCESS
} else {
transcode = constants.FILE_TRANSCODE_FAILED
}
_, err = db.Exec(ctx, "UPDATE files SET transcode = $2 WHERE id = $1", ts.Task.FileID, transcode)
if err != nil {
slog.ErrorContext(ctx, "Updating File transcode", "err", err)
return
}
}
// Tell Worker to Delete Finished Tasks
_, err := rpcServer.Call(ctx, w.Conn, "task-delete", taskID, nil)
if err != nil {
slog.ErrorContext(ctx, "Deleting Finished Task From Worker", "err", err)
@ -264,7 +277,7 @@ func updateWorkerTaskStatus(ctx context.Context) {
} else {
// TODO wait for 5 minutes for worker to reconnect
// Set Task Status to Unknown for Unfinished Tasks which where assigned to this not connected worker, right now they just get stuck
// Set Task Status to Unknown for Unfinished Tasks which where assigned to this not connected worker, right now they just get stuck if worker does not reconnect
}
}