Files
vctp2/server/handler/updateCleanup.go
Nathan Coad f2d6b3158b
All checks were successful
continuous-integration/drone/push Build is passing
Refactor code to use 'any' type and improve context handling
2026-02-18 16:16:27 +11:00

53 lines
1.6 KiB
Go

package handler
import (
"fmt"
"net/http"
)
// UpdateCleanup removes orphaned update records.
// @Summary Cleanup updates (deprecated)
// @Description Deprecated: Removes update records that are no longer associated with a VM.
// @Tags maintenance
// @Deprecated
// @Produce text/plain
// @Success 200 {string} string "Cleanup completed"
// @Failure 500 {string} string "Server error"
// @Router /api/cleanup/updates [delete]
func (h *Handler) UpdateCleanup(w http.ResponseWriter, r *http.Request) {
if h.denyLegacyAPI(w, "/api/cleanup/updates") {
return
}
ctx, cancel := withRequestTimeout(r, defaultRequestTimeout)
defer cancel()
/*
// Get the current time
now := time.Now()
// Get the start of the current day (midnight today)
midnightToday := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
// Convert to Unix time
unixTime := midnightToday.Unix()
// create the database parameters
params := queries.CleanupUpdatesParams{
UpdateType: "diskchange",
UpdateTime: sql.NullInt64{Int64: unixTime, Valid: unixTime > 0},
}
h.Logger.Debug("database params", "params", params)
err := h.Database.Queries().CleanupUpdates(ctx, params)
*/
//err := h.Database.Queries().InventoryCleanupTemplates(ctx)
err := h.Database.Queries().CleanupUpdatesNullVm(ctx)
if err != nil {
h.Logger.Error("Error received cleaning updates table", "error", err)
writeJSONError(w, http.StatusInternalServerError, fmt.Sprintf("Delete Request unsuccessful %s", err))
} else {
h.Logger.Debug("Processed update cleanup successfully")
writeJSONOKMessage(w, "Processed update cleanup successfully")
}
}