From fa600d6fc98427ca9b43381379062294a273eaaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 19 Jul 2022 12:00:44 +0200 Subject: [PATCH] Cleanup: rename `mustHostname()` to `workerName()` The function determines the worker's name. The fact that it can use the hostname for this isn't that relevant. --- internal/worker/registration.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/worker/registration.go b/internal/worker/registration.go index b165fffb..a2e9acfd 100644 --- a/internal/worker/registration.go +++ b/internal/worker/registration.go @@ -92,7 +92,7 @@ func register(ctx context.Context, cfg WorkerConfig, client FlamencoClient) Work secretKey := hex.EncodeToString(secret) req := api.RegisterWorkerJSONRequestBody{ - Name: mustHostname(), + Name: workerName(), Platform: runtime.GOOS, Secret: secretKey, SupportedTaskTypes: cfg.TaskTypes, @@ -151,7 +151,7 @@ func signOn(ctx context.Context, cfg WorkerConfig, client FlamencoClient) (api.W logger := log.With().Str("manager", cfg.ManagerURL).Logger() req := api.SignOnJSONRequestBody{ - Name: mustHostname(), + Name: workerName(), SupportedTaskTypes: cfg.TaskTypes, SoftwareVersion: appinfo.ApplicationVersion, } @@ -186,8 +186,8 @@ func signOn(ctx context.Context, cfg WorkerConfig, client FlamencoClient) (api.W return startupState, nil } -// mustHostname either the hostname or logs a fatal error. -func mustHostname() string { +// workerName returns a suitable name for the worker. Errors are fatal. +func workerName() string { name, ok := os.LookupEnv(workerNameEnvVariable) if ok && name != "" { name = strings.TrimSpace(name)