jynx/main.go

63 lines
1.3 KiB
Go
Raw Normal View History

2023-05-29 21:21:50 +00:00
package main
import (
"os"
"strconv"
"time"
"git.stinnesbeck.com/go/jynx/ci/woodpecker"
"git.stinnesbeck.com/go/jynx/scaler"
"git.stinnesbeck.com/go/log"
)
func main() {
checkEnv()
w := woodpecker.NewServer(
"https://woodpecker.fftdf.de",
os.Getenv("WOODPECKER_PROMETHEUS_AUTH_TOKEN"),
)
interval := time.Duration(5)
if i := os.Getenv("SCALER_POLL_INTERVAL"); i != "" {
envInterval, err := strconv.Atoi(i)
if err != nil {
log.PrintError("can't parse SCALER_POLL_INTERVAL", err)
os.Exit(1)
}
// overwrite default interval with the one provided by env variable
interval = time.Duration(envInterval)
}
ticker := time.Tick(interval * time.Second)
// start scaler once
if err := scaler.Start(&w); err != nil {
panic(err)
}
// start scaler every tick
for range ticker {
if err := scaler.Start(&w); err != nil {
panic(err)
}
}
}
func checkEnv() {
switch "" {
case os.Getenv("WOODPECKER_HOSTNAME"):
log.PrintError("WOODPECKER_HOSTNAME not set")
case os.Getenv("WOODPECKER_AGENT_SECRET"):
log.PrintError("WOODPECKER_AGENT_SECRET not set")
os.Exit(1)
case os.Getenv("HCLOUD_PREFIX"):
log.PrintError("HCLOUD_PREFIX not set")
os.Exit(1)
case os.Getenv("WOODPECKER_PROMETHEUS_AUTH_TOKEN"):
log.PrintError("WOODPECKER_PROMETHEUS_AUTH_TOKEN not set")
os.Exit(1)
}
}