Refactor code to use 'any' type and improve context handling
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-02-18 16:16:27 +11:00
parent 6517a30fa2
commit f2d6b3158b
36 changed files with 197 additions and 175 deletions

View File

@@ -41,7 +41,8 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
var unixTimestamp int64
re := regexp.MustCompile(`/([^/]+)/[^/]+\.vmdk$`)
ctx := context.Background()
ctx, cancel := withRequestTimeout(r, defaultRequestTimeout)
defer cancel()
reqBody, err := io.ReadAll(r.Body)
if err != nil {
@@ -189,7 +190,7 @@ func (h *Handler) VmModifyEvent(w http.ResponseWriter, r *http.Request) {
// If we found a disk change belonging to this VM then recalculate the disk size
if diskChangeFound {
params.UpdateType = "diskchange"
diskSize := h.calculateNewDiskSize(event)
diskSize := h.calculateNewDiskSize(ctx, event)
params.NewProvisionedDisk = sql.NullFloat64{Float64: diskSize, Valid: diskSize > 0}
}
}
@@ -333,7 +334,7 @@ func (h *Handler) processConfigChanges(configChanges string) []map[string]string
return result
}
func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64 {
func (h *Handler) calculateNewDiskSize(ctx context.Context, event models.CloudEventReceived) float64 {
var diskSize float64
var totalDiskBytes int64
h.Logger.Debug("connecting to vcenter")
@@ -368,7 +369,9 @@ func (h *Handler) calculateNewDiskSize(event models.CloudEventReceived) float64
}
}
_ = vc.Logout(context.Background())
logoutCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second)
defer cancel()
_ = vc.Logout(logoutCtx)
h.Logger.Debug("Calculated new disk size", "value", diskSize)