diff --git a/server/task.go b/server/task.go index 8e32fa9..e19d624 100644 --- a/server/task.go +++ b/server/task.go @@ -328,6 +328,7 @@ type QueuedTask struct { Type constants.TaskType FileID int `json:"file_id"` FileMD5 []byte `json:"file_md5" db:"md5"` + FileExtension string `json:"file_extension"` Data json.RawMessage FfmpegCommand types.FFmpegCommand `json:"ffmpeg_command" db:"ffmpeg_command"` } @@ -344,7 +345,7 @@ func assignQueuedTasks(ctx context.Context) error { 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 AND f.status = $2 ORDER BY type DESC", constants.TASK_STATUS_QUEUED, constants.FILE_STATUS_EXISTS) + rows, err := db.Query(ctx, "SELECT t.id as id, t.type as type, t.file_id as file_id, f.md5 as md5, substring(f.path FROM '\\.([^\\.]*)$') AS file_extension, 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 AND f.status = $2 ORDER BY type DESC", constants.TASK_STATUS_QUEUED, constants.FILE_STATUS_EXISTS) if err != nil { return fmt.Errorf("Query Queued Tasks: %w", err) } @@ -353,6 +354,8 @@ func assignQueuedTasks(ctx context.Context) error { return fmt.Errorf("Collect Queued Tasks: %w", err) } + // TODO, allow overwriting of extension + //slog.Info("Assigning Queued Tasks", "count", len(queuedTasks)) if len(queuedTasks) == 0 { @@ -406,6 +409,7 @@ func assignQueuedTasks(ctx context.Context) error { Type: queuedTasks[lastAssigned].Type, FileID: queuedTasks[lastAssigned].FileID, FileMD5: queuedTasks[lastAssigned].FileMD5, + FileExtension: queuedTasks[lastAssigned].FileExtension, Data: queuedTasks[lastAssigned].Data, FfmpegCommand: queuedTasks[lastAssigned].FfmpegCommand, } diff --git a/task/healthcheck.go b/task/healthcheck.go index 9039634..0256167 100644 --- a/task/healthcheck.go +++ b/task/healthcheck.go @@ -17,7 +17,7 @@ func RunHealthCheck(conf config.Config, t *types.Task, data types.HealthCheckDat l := log.GetTaskLogger(t) // TODO Figure out how to get correct file ending - path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-health-%v-%v.mkv", t.ID, t.FileID)) + path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-health-%v-%v."+t.FileExtension, t.ID, t.FileID)) // Set ffmpeg input path if len(t.FfmpegCommand.InputFiles) == 0 { diff --git a/task/transcode.go b/task/transcode.go index 9d6a143..e1a8c41 100644 --- a/task/transcode.go +++ b/task/transcode.go @@ -17,8 +17,8 @@ func RunTranscode(conf config.Config, t *types.Task, data types.TranscodeData) { l := log.GetTaskLogger(t) // TODO Figure out how to get correct file ending - src_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-src-%v-%v.mkv", t.ID, t.FileID)) - dst_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-dst-%v-%v.mkv", t.ID, t.FileID)) + src_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-src-%v-%v."+t.FileExtension, t.ID, t.FileID)) + dst_path := filepath.Join(conf.Worker.TempDir, fmt.Sprintf("morffix-dst-%v-%v."+t.FileExtension, t.ID, t.FileID)) // Set ffmpeg input path if len(t.FfmpegCommand.InputFiles) == 0 { diff --git a/types/task.go b/types/task.go index 766ba1b..552503b 100644 --- a/types/task.go +++ b/types/task.go @@ -10,6 +10,7 @@ type TaskStart struct { ID int `json:"id"` FileID int `json:"file_id"` FileMD5 []byte `json:"file_md5"` + FileExtension string `json:"file_extension"` Type constants.TaskType `json:"type"` Data json.RawMessage FfmpegCommand FFmpegCommand `json:"ffmpeg_command"` @@ -19,6 +20,7 @@ type Task struct { ID int `json:"id"` FileID int `json:"file_id"` FileMD5 []byte `json:"md5"` + FileExtension string `json:"file_extension"` Type constants.TaskType `json:"type"` Status constants.TaskStatus `json:"status"` FfmpegCommand FFmpegCommand `json:"ffmpeg_command"`