Skip to content

Commit

Permalink
move set auto max procs to a function
Browse files Browse the repository at this point in the history
Signed-off-by: nitishfy <justnitish06@gmail.com>
  • Loading branch information
nitishfy committed Oct 3, 2024
1 parent f76a114 commit 376c62a
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
log "github.com/sirupsen/logrus"
"go.uber.org/automaxprocs/maxprocs"
"os"
"path/filepath"
Expand All @@ -24,16 +25,14 @@ const (
)

func main() {
_, err := maxprocs.Set()
if err != nil {
return
}
var command *cobra.Command

binaryName := filepath.Base(os.Args[0])
if val := os.Getenv(binaryNameEnv); val != "" {
binaryName = val
}
setAutoMaxProcs(binaryName)

switch binaryName {
case "argocd", "argocd-linux-amd64", "argocd-darwin-amd64", "argocd-windows-amd64.exe":
command = cli.NewCommand()
Expand Down Expand Up @@ -63,3 +62,21 @@ func main() {
os.Exit(1)
}
}

// setAutoMaxProcs sets the GOMAXPROCS value based on the binary name.
// It suppresses logs for CLI binaries and logs the setting for services.
func setAutoMaxProcs(binaryName string) {
isCLI := binaryName == "argocd" ||
binaryName == "argocd-linux-amd64" ||
binaryName == "argocd-darwin-amd64" ||
binaryName == "argocd-windows-amd64.exe"

if isCLI {
_, _ = maxprocs.Set() // Intentionally ignore errors for CLI binaries
} else {
_, err := maxprocs.Set(maxprocs.Logger(log.Debugf))
if err != nil {
log.Errorf("Error setting GOMAXPROCS: %v", err)
}
}
}

0 comments on commit 376c62a

Please sign in to comment.