update database schema to avoid bool confusion
Some checks are pending
CI / Lint (push) Waiting to run
CI / Test (push) Waiting to run
CI / End-to-End (push) Waiting to run
CI / Publish Docker (push) Blocked by required conditions
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-09-27 11:07:51 +10:00
parent b371e28469
commit c691763430
8 changed files with 214 additions and 72 deletions

46
main.go
View File

@@ -21,10 +21,11 @@ import (
)
var (
bindDisableTls bool
sha1ver string // sha1 revision used to build the program
buildTime string // when the executable was built
cronFrequency time.Duration
bindDisableTls bool
sha1ver string // sha1 revision used to build the program
buildTime string // when the executable was built
cronFrequency time.Duration
cronInvFrequency time.Duration
)
func main() {
@@ -125,17 +126,29 @@ func main() {
Settings: s,
}
cronFrequencyString := os.Getenv("VCENTER_POLLING_SECONDS")
cronFrequencyString := os.Getenv("VCENTER_EVENT_POLLING_SECONDS")
if cronFrequencyString != "" {
cronFrequency, err = time.ParseDuration(cronFrequencyString)
if err != nil {
slog.Error("Can't convert VCENTER_POLLING_SECONDS value to time duration. Defaulting to 60s", "value", cronFrequencyString, "error", err)
slog.Error("Can't convert VCENTER_EVENT_POLLING_SECONDS value to time duration. Defaulting to 60s", "value", cronFrequencyString, "error", err)
cronFrequency = time.Second * 60
}
} else {
cronFrequency = time.Second * 60
}
logger.Debug("Setting VM polling cronjob frequency to", "frequency", cronFrequency)
logger.Debug("Setting VM event polling cronjob frequency to", "frequency", cronFrequency)
cronInventoryFrequencyString := os.Getenv("VCENTER_INVENTORY_POLLING_SECONDS")
if cronInventoryFrequencyString != "" {
cronInvFrequency, err = time.ParseDuration(cronInventoryFrequencyString)
if err != nil {
slog.Error("Can't convert VCENTER_INVENTORY_POLLING_SECONDS value to time duration. Defaulting to 3600s", "value", cronInventoryFrequencyString, "error", err)
cronInvFrequency = time.Second * 3600
}
} else {
cronInvFrequency = time.Second * 3600
}
logger.Debug("Setting VM inventory polling cronjob frequency to", "frequency", cronInvFrequency)
// start background processing for events stored in events table
startsAt := time.Now().Add(time.Second * 10)
@@ -147,24 +160,25 @@ func main() {
gocron.WithStartAt(gocron.WithStartDateTime(startsAt)),
)
if err != nil {
logger.Error("failed to start cron jobs", "error", err)
logger.Error("failed to start event processing cron job", "error", err)
os.Exit(1)
}
logger.Debug("Created event processing cron job", "job", job.ID())
startsAt2 := time.Now().Add(time.Second * 10)
// start background checks of vcenter inventory
startsAt2 := time.Now().Add(time.Second * 300)
job2, err := c.NewJob(
gocron.DurationJob(cronFrequency),
gocron.DurationJob(cronInvFrequency),
gocron.NewTask(func() {
ct.RunVcenterPoll(ctx, logger)
}), gocron.WithSingletonMode(gocron.LimitModeReschedule),
gocron.WithStartAt(gocron.WithStartDateTime(startsAt2)),
)
if err != nil {
logger.Error("failed to start cron jobs", "error", err)
logger.Error("failed to start vcenter inventory cron job", "error", err)
os.Exit(1)
}
logger.Debug("Created vcenter polling cron job", "job", job2.ID())
logger.Debug("Created vcenter inventory cron job", "job", job2.ID())
// start cron scheduler
c.Start()
@@ -176,11 +190,11 @@ func main() {
cancel,
bindAddress,
server.WithRouter(router.New(logger, database, buildTime, sha1ver, runtime.Version())),
server.SetTls(bindDisableTls),
server.SetCertificate(tlsCertFilename),
server.SetPrivateKey(tlsKeyFilename),
)
svr.DisableTls(bindDisableTls)
svr.SetCertificate(tlsCertFilename)
svr.SetPrivateKey(tlsKeyFilename)
//logger.Debug("Server configured", "object", svr)
svr.StartAndWait()