From 0d7d3d305c9a3f6c1234f8c85204667242ade504 Mon Sep 17 00:00:00 2001 From: Nate Sales Date: Mon, 2 Sep 2024 17:44:54 -0400 Subject: [PATCH] refactor: extract lockfile check to function --- pkg/process/process.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/process/process.go b/pkg/process/process.go index 11f825d5..a6ea0db5 100644 --- a/pkg/process/process.go +++ b/pkg/process/process.go @@ -160,6 +160,8 @@ func parseStatics(all map[string]string, v4 map[string]string, v6 map[string]str } // Load loads a configuration file from a YAML file +// +//gocyclo:ignore func Load(configBlob []byte) (*config.Config, error) { var c config.Config c.Init() @@ -618,9 +620,8 @@ func peer(peerName string, peerData *config.Peer, c *config.Config, wg *sync.Wai return nil } -// Run runs the full data generation procedure -func Run(configFilename, lockFile, version string, noConfigure, dryRun, withdraw bool) { - // Check lockfile +// lock prevents multiple instances of Pathvector from running +func lock(lockFile string) { if lockFile != "" { if _, err := os.Stat(lockFile); err == nil { log.Fatal("Lockfile exists, exiting") @@ -635,6 +636,11 @@ func Run(configFilename, lockFile, version string, noConfigure, dryRun, withdraw log.Fatalf("Accessing lockfile: %v", err) } } +} + +// Run runs the full data generation procedure +func Run(configFilename, lockFile, version string, noConfigure, dryRun, withdraw bool) { + lock(lockFile) log.Infof("Starting Pathvector %s", version) startTime := time.Now()