From 3a786d60fd86802fc6e3fa2f0cc12c02a1751e85 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 22 Sep 2025 01:50:15 -0500 Subject: adding url debugging --- Makefile | 2 +- README | 2 ++ argv.go | 10 +++++++--- daemon.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ main.go | 19 ++++++++++++++++++- watchdog.go | 45 --------------------------------------------- 6 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 daemon.go delete mode 100644 watchdog.go diff --git a/Makefile b/Makefile index 636eafb..fd94d4e 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= all: build ./zood --version - ./zood + ./zood test build: goimports GO111MODULE=off go build -v -x \ diff --git a/README b/README index c9c8ffe..55ecd7e 100644 --- a/README +++ b/README @@ -1 +1,3 @@ This is the zookeeper daemon. + +It is simple. It's just designed to keep packages up to date. diff --git a/argv.go b/argv.go index 101fab8..0efa3c9 100644 --- a/argv.go +++ b/argv.go @@ -16,9 +16,13 @@ import ( var argv args type args struct { - Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` - Port int `arg:"--port" default:"2521" help:"port to run on"` - URL string `arg:"--url" help:"url to use"` + Test *EmptyCmd `arg:"subcommand:test" help:"New to forge? This is for you.'"` + Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` + Port int `arg:"--port" default:"2521" help:"port to run on"` + URL string `arg:"--url" help:"url to use"` +} + +type EmptyCmd struct { } func (args) Version() string { diff --git a/daemon.go b/daemon.go new file mode 100644 index 0000000..f92907f --- /dev/null +++ b/daemon.go @@ -0,0 +1,46 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "fmt" + "os" + "time" +) + +// timeFunction takes a function as an argument and returns the execution time. +func TimeFunction(f func()) time.Duration { + startTime := time.Now() // Record the start time + f() // Execute the function + return time.Since(startTime) // Calculate the elapsed time +} + +// sends updates to zookeeper +func zood() { + me.dog = time.NewTicker(me.pollDelay) + defer me.dog.Stop() + done := make(chan bool) + for { + select { + case <-done: + fmt.Println("Done!") + return + case _ = <-me.dog.C: + s := me.machine.UpdatePackages() + me.failcount += 1 + sendMachine(s) + + if me.failcount > 20 { + os.Exit(0) + } + } + } + /* + // this example would exit/destroy the ticker in 10 seconds + go func() { + time.Sleep(10 * time.Second) + done <- true + }() + */ +} diff --git a/main.go b/main.go index 3f685dd..581ef09 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ func main() { } me = new(stuff) - me.urlbase = "http://zookeeper.grid.wit.com:8080" + me.urlbase = "http://zookeeper.chap.wit.com:8080" if argv.URL != "" { log.Info("USING ARGV URL:", argv.URL) me.urlbase = argv.URL @@ -45,5 +45,22 @@ func main() { me.machine = zoopb.InitMachine() + if argv.Test != nil { + testURL(me.urlbase, me.machine) + os.Exit(0) + } + zood() // talks to zookeeper } + +func testURL(urlbase string, pb *zoopb.Machine) error { + newpb, wsPB, err := pb.HttpPost(urlbase, "test") + if err != nil { + log.Info("got error:", err) + return err + } + wsPB.DumpClient() + newpb.Dump() + log.Info("got error:", err) + return err +} diff --git a/watchdog.go b/watchdog.go deleted file mode 100644 index d9491b9..0000000 --- a/watchdog.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017-2025 WIT.COM Inc. All rights reserved. -// Use of this source code is governed by the GPL 3.0 - -package main - -import ( - "fmt" - "os" - "time" -) - -// timeFunction takes a function as an argument and returns the execution time. -func TimeFunction(f func()) time.Duration { - startTime := time.Now() // Record the start time - f() // Execute the function - return time.Since(startTime) // Calculate the elapsed time -} - -func zood() { - me.dog = time.NewTicker(me.pollDelay) - defer me.dog.Stop() - done := make(chan bool) - for { - select { - case <-done: - fmt.Println("Done!") - return - case _ = <-me.dog.C: - s := me.machine.UpdatePackages() - me.failcount += 1 - sendMachine(s) - - if me.failcount > 20 { - os.Exit(0) - } - } - } - /* - // this example would exit/destroy the ticker in 10 seconds - go func() { - time.Sleep(10 * time.Second) - done <- true - }() - */ -} -- cgit v1.2.3