Skip to content

Commit

Permalink
genie working
Browse files Browse the repository at this point in the history
  • Loading branch information
timam committed Oct 23, 2023
1 parent 1a9267a commit ded654a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 53 deletions.
2 changes: 0 additions & 2 deletions svc/watcher/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@ COPY ./svc/watcher /statuz/svc/watcher

RUN go build -o /statuz/bin/watcher -ldflags '-w -s' -tags netgo -a -installsuffix cgo -v ./svc/watcher

FROM alpine:edge
COPY --from=build /statuz/bin/watcher /statuz/bin/watcher
ENTRYPOINT ["/statuz/bin/watcher"]
105 changes: 54 additions & 51 deletions svc/watcher/main.go
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
package main

import (
"errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/statuzproj/statuz/utils/evictedconf"
"github.com/statuzproj/statuz/utils/healthz"
"log"
"net/http"
"sync"
)

func main() {
var wg sync.WaitGroup

// Start the HTTP server in a goroutine
wg.Add(1)
go func() {
defer wg.Done()

http.HandleFunc("/healthz", healthz.HealthCheck)
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatalf("HTTP server error: %v", err)
}
}()

// Start the watcher in another goroutine
wg.Add(1)
go func() {
defer wg.Done()

err := start()
if err != nil {
log.Fatalf("Error starting watcher: %v", err)
}
}()
//
//func main() {
// var wg sync.WaitGroup
//
// // Start the HTTP server in a goroutine
// wg.Add(1)
// go func() {
// defer wg.Done()
//
// http.HandleFunc("/healthz", healthz.HealthCheck)
// http.Handle("/metrics", promhttp.Handler())
// err := http.ListenAndServe(":8080", nil)
// if err != nil {
// log.Fatalf("HTTP server error: %v", err)
// }
// }()
//
// // Start the watcher in another goroutine
// wg.Add(1)
// go func() {
// defer wg.Done()
//
// err := start()
// if err != nil {
// log.Fatalf("Error starting watcher: %v", err)
// }
// }()
//
// // Wait for all goroutines to complete before exiting
// wg.Wait()
//}
//
//func start() error {
// env, err := evictedconf.GetEnvVars()
// if err != nil {
// return err
// }
//
// if env.Type == "webpage" {
// err := watchPage(env.Endpoint, env.Interval)
// if err != nil {
// return err
// }
// } else if env.Type == "ip" {
// watchIp(env.Endpoint, env.Port, env.Interval)
// } else {
// return errors.New("Unsupported watch type: " + env.Type)
// }
// return nil
//}

// Wait for all goroutines to complete before exiting
wg.Wait()
}

func start() error {
env, err := evictedconf.GetEnvVars()
if err != nil {
return err
}

if env.Type == "webpage" {
err := watchPage(env.Endpoint, env.Interval)
if err != nil {
return err
}
} else if env.Type == "ip" {
watchIp(env.Endpoint, env.Port, env.Interval)
} else {
return errors.New("Unsupported watch type: " + env.Type)
}
return nil
func main() {
log.Println("Work in Progress!!")
http.HandleFunc("/healthz", healthz.HealthCheck)
http.ListenAndServe(":8080", nil)
}

0 comments on commit ded654a

Please sign in to comment.