From 377583c9e2b1ff638a65edad1f8736dbb1c69909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 29 Jul 2022 09:47:30 +0200 Subject: [PATCH] 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 --- cmd/flamenco-worker/find_exes.go | 23 +++++++++++++++++++++++ cmd/flamenco-worker/main.go | 15 --------------- internal/find_blender/find_blender.go | 7 +++++++ 3 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 cmd/flamenco-worker/find_exes.go diff --git a/cmd/flamenco-worker/find_exes.go b/cmd/flamenco-worker/find_exes.go new file mode 100644 index 00000000..e8de3f95 --- /dev/null +++ b/cmd/flamenco-worker/find_exes.go @@ -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") + } +} diff --git a/cmd/flamenco-worker/main.go b/cmd/flamenco-worker/main.go index 986c8acd..a0c981d8 100644 --- a/cmd/flamenco-worker/main.go +++ b/cmd/flamenco-worker/main.go @@ -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") - } -} diff --git a/internal/find_blender/find_blender.go b/internal/find_blender/find_blender.go index 43126e62..a52d4f5f 100644 --- a/internal/find_blender/find_blender.go +++ b/internal/find_blender/find_blender.go @@ -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) {