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.
This commit is contained in:
Sybren A. Stüvel 2022-07-19 12:00:44 +02:00
parent d425bca5cf
commit fa600d6fc9

View File

@ -92,7 +92,7 @@ func register(ctx context.Context, cfg WorkerConfig, client FlamencoClient) Work
secretKey := hex.EncodeToString(secret) secretKey := hex.EncodeToString(secret)
req := api.RegisterWorkerJSONRequestBody{ req := api.RegisterWorkerJSONRequestBody{
Name: mustHostname(), Name: workerName(),
Platform: runtime.GOOS, Platform: runtime.GOOS,
Secret: secretKey, Secret: secretKey,
SupportedTaskTypes: cfg.TaskTypes, 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() logger := log.With().Str("manager", cfg.ManagerURL).Logger()
req := api.SignOnJSONRequestBody{ req := api.SignOnJSONRequestBody{
Name: mustHostname(), Name: workerName(),
SupportedTaskTypes: cfg.TaskTypes, SupportedTaskTypes: cfg.TaskTypes,
SoftwareVersion: appinfo.ApplicationVersion, SoftwareVersion: appinfo.ApplicationVersion,
} }
@ -186,8 +186,8 @@ func signOn(ctx context.Context, cfg WorkerConfig, client FlamencoClient) (api.W
return startupState, nil return startupState, nil
} }
// mustHostname either the hostname or logs a fatal error. // workerName returns a suitable name for the worker. Errors are fatal.
func mustHostname() string { func workerName() string {
name, ok := os.LookupEnv(workerNameEnvVariable) name, ok := os.LookupEnv(workerNameEnvVariable)
if ok && name != "" { if ok && name != "" {
name = strings.TrimSpace(name) name = strings.TrimSpace(name)