add temp endpoint for db cleanup
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-26 12:15:39 +10:00
parent 3b53455343
commit dd13fd6759
5 changed files with 77 additions and 14 deletions

View File

@@ -0,0 +1,40 @@
package handler
import (
"context"
"database/sql"
"fmt"
"net/http"
"time"
"vctp/db/queries"
)
// VmUpdate receives the CloudEvent for a VM modification or move
func (h *Handler) UpdateCleanup(w http.ResponseWriter, r *http.Request) {
// 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(context.Background(), params)
if err != nil {
h.Logger.Error("Error received cleaning updates table", "error", err)
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Delete Request unsuccessful %s\n", err)
} else {
h.Logger.Debug("Processed update cleanup successfully")
w.WriteHeader(http.StatusOK)
// TODO - return some JSON
fmt.Fprintf(w, "Processed update cleanup successfully")
}
}

View File

@@ -85,19 +85,19 @@ type ConfigChangesReceived struct {
// This probably needs more fields added so not in use yet
type ConfigSpec struct {
AlternateGuestName string `json:"AlternateGuestName"`
Annotation string `json:"Annotation"`
BootOptions any `json:"BootOptions"`
ChangeTrackingEnabled any `json:"ChangeTrackingEnabled"`
ChangeVersion string `json:"ChangeVersion"`
ConsolePreferences any `json:"ConsolePreferences"`
CPUAffinity any `json:"CpuAffinity"`
CPUAllocation any `json:"CpuAllocation"`
CPUFeatureMask any `json:"CpuFeatureMask"`
CPUHotAddEnabled any `json:"CpuHotAddEnabled"`
CPUHotRemoveEnabled any `json:"CpuHotRemoveEnabled"`
CreateDate time.Time `json:"CreateDate"`
Crypto any `json:"Crypto"`
AlternateGuestName string `json:"AlternateGuestName"`
Annotation string `json:"Annotation"`
BootOptions any `json:"BootOptions"`
ChangeTrackingEnabled any `json:"ChangeTrackingEnabled"`
ChangeVersion string `json:"ChangeVersion"`
ConsolePreferences any `json:"ConsolePreferences"`
CPUAffinity any `json:"CpuAffinity"`
CPUAllocation any `json:"CpuAllocation"`
CPUFeatureMask any `json:"CpuFeatureMask"`
CPUHotAddEnabled any `json:"CpuHotAddEnabled"`
CPUHotRemoveEnabled any `json:"CpuHotRemoveEnabled"`
CreateDate string `json:"CreateDate"` // Modified from time.Time
Crypto any `json:"Crypto"`
DeviceChange []struct {
Backing any `json:"Backing"`
Device struct {
@@ -151,7 +151,7 @@ type ConfigSpec struct {
Profile []struct {
ProfileData struct {
ExtensionKey string `json:"ExtensionKey"`
ObjectData time.Time `json:"ObjectData"`
ObjectData time.Time `json:"ObjectData"` // Modified from time.Time
} `json:"ProfileData"`
ProfileID string `json:"ProfileId"`
ProfileParams any `json:"ProfileParams"`

View File

@@ -26,6 +26,8 @@ func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver st
mux.HandleFunc("/api/event/vm/modify", h.VmModify)
mux.HandleFunc("/api/event/vm/delete", h.VmDelete)
mux.HandleFunc("/api/import/vm", h.VmImport)
// temporary endpoint
mux.HandleFunc("/api/cleanup/updates", h.UpdateCleanup)
return middleware.NewLoggingMiddleware(logger, mux)
}