Compare commits

...

2 Commits

Author SHA1 Message Date
lerentis 45ebc96c13 Merge pull request 'hopefully fix time comparison' (#9) from bugfix/tt/costoptimizedmode into main
ci/woodpecker/push/main Pipeline was successful Details
Reviewed-on: #9
2024-02-03 23:14:55 +00:00
Tobias Trabelsi cb1a931b4c
hopefully fix time comparison
ci/woodpecker/pr/pr Pipeline was successful Details
2024-02-04 00:08:43 +01:00
2 changed files with 6 additions and 6 deletions

View File

@ -85,13 +85,13 @@ func Decom(cfg *config.Config, ownedNodes []hcloud.Server) {
}
log.WithFields(log.Fields{
"Caller": "Decom",
}).Debugf("Node %s is running for %f", server.Name, runtime.Minutes())
}).Debugf("Node %s is running for %d", server.Name, runtime.Minute())
// Check if next check if sooner than the 60 Minute mark of the next hetzner check
// https://docs.hetzner.com/cloud/billing/faq/#how-do-you-bill-your-servers
if (runtime + time.Duration(cfg.CheckInterval)*time.Minute) < 60 {
if time.Duration(runtime.Add(time.Duration(cfg.CheckInterval)*time.Minute).Minute()) < (60 * time.Minute) {
log.WithFields(log.Fields{
"Caller": "Decom",
}).Infof("Skipping node termination of %s (running for %f Minutes) in Cost Optimized Mode", server.Name, runtime.Minutes())
}).Infof("Skipping node termination of %s (running for %d Minutes) in Cost Optimized Mode", server.Name, runtime.Minute())
continue
}
}

View File

@ -175,11 +175,11 @@ func RefreshNodeInfo(cfg *config.Config, serverID int) (*hcloud.Server, error) {
return server, nil
}
func CheckRuntime(cfg *config.Config, server *hcloud.Server) (time.Duration, error) {
func CheckRuntime(cfg *config.Config, server *hcloud.Server) (time.Time, error) {
server, err := RefreshNodeInfo(cfg, server.ID)
now := time.Now()
if err != nil {
return time.Duration(0), errors.New(fmt.Sprintf("Could not check Runtime: %s", err.Error()))
return time.Time{}, errors.New(fmt.Sprintf("Could not check Runtime: %s", err.Error()))
}
return server.Created.Sub(now), nil
return server.Created.Add(time.Duration(now.Minute())), nil
}