Cleanup: worker, move FFmpeg-finding at startup into its own file

Just a move of code from `main.go` to a dedicated file in the same package.

No functional changes
This commit is contained in:
Sybren A. Stüvel 2022-07-29 09:47:30 +02:00
parent fb5501028d
commit 377583c9e2
3 changed files with 30 additions and 15 deletions

@ -0,0 +1,23 @@
package main
import (
"errors"
"io/fs"
"github.com/rs/zerolog/log"
"git.blender.org/flamenco/internal/find_ffmpeg"
)
// findFFmpeg tries to find FFmpeg, in order to show its version (if found) or a warning (if not).
func findFFmpeg() {
result, err := find_ffmpeg.Find()
switch {
case errors.Is(err, fs.ErrNotExist):
log.Warn().Msg("FFmpeg could not be found on this system, render jobs may not run correctly")
case err != nil:
log.Warn().Err(err).Msg("there was an unexpected error finding FFmepg on this system, render jobs may not run correctly")
default:
log.Info().Str("path", result.Path).Str("version", result.Version).Msg("FFmpeg found on this system")
}
}

@ -7,7 +7,6 @@ import (
"errors"
"flag"
"fmt"
"io/fs"
"net/url"
"os"
"os/signal"
@ -21,7 +20,6 @@ import (
"github.com/rs/zerolog/log"
"git.blender.org/flamenco/internal/appinfo"
"git.blender.org/flamenco/internal/find_ffmpeg"
"git.blender.org/flamenco/internal/worker"
"git.blender.org/flamenco/internal/worker/cli_runner"
)
@ -259,16 +257,3 @@ func logFatalManagerDiscoveryError(err error, discoverTimeout time.Duration) {
log.Fatal().Err(err).Msg("auto-discovery error")
}
}
// findFFmpeg tries to find FFmpeg, in order to show its version (if found) or a warning (if not).
func findFFmpeg() {
result, err := find_ffmpeg.Find()
switch {
case errors.Is(err, fs.ErrNotExist):
log.Warn().Msg("FFmpeg could not be found on this system, render jobs may not run correctly")
case err != nil:
log.Warn().Err(err).Msg("there was an unexpected error finding FFmepg on this system, render jobs may not run correctly")
default:
log.Info().Str("path", result.Path).Str("version", result.Version).Msg("FFmpeg found on this system")
}
}

@ -35,6 +35,13 @@ type CheckBlenderResult struct {
Source api.BlenderPathSource
}
// Find returns the path of a `blender` executable,
// If there is one associated with .blend files, and the current platform is
// supported to query those, that one is used. Otherwise $PATH is searched.
func Find(ctx context.Context) (CheckBlenderResult, error) {
return CheckBlender(ctx, "")
}
// FileAssociation returns the full path of a Blender executable, by inspecting file association with .blend files.
// `ErrNotAvailable` is returned if no "blender finder" is available for the current platform.
func FileAssociation() (string, error) {