Don't run assigning multiple times

This commit is contained in:
Samuel Lorch 2024-07-06 17:08:28 +02:00
parent f4219fe0b2
commit 77d7a8624c

View file

@ -332,7 +332,18 @@ type QueuedTask struct {
FfmpegCommand types.FFmpegCommand `json:"ffmpeg_command" db:"ffmpeg_command"`
}
var assignRunning = false
func assignQueuedTasks(ctx context.Context) error {
if assignRunning {
return nil
}
assignRunning = true
defer func() {
assignRunning = false
}()
rows, err := db.Query(ctx, "SELECT t.id as id, t.type as type, t.file_id as file_id, f.md5 as md5, t.data as data, fc.data as ffmpeg_command FROM tasks t INNER JOIN files f ON f.id = t.file_id INNER JOIN ffmpeg_commands fc ON fc.id = t.ffmpeg_command_id WHERE t.status = $1", constants.TASK_STATUS_QUEUED)
if err != nil {
return fmt.Errorf("Query Queued Tasks: %w", err)