cleanup updates with no vm reference
This commit is contained in:
@@ -75,6 +75,11 @@ DELETE FROM "Updates"
|
|||||||
WHERE "UpdateType" = sqlc.arg('updateType') AND "UpdateTime" <= sqlc.arg('updateTime')
|
WHERE "UpdateType" = sqlc.arg('updateType') AND "UpdateTime" <= sqlc.arg('updateTime')
|
||||||
RETURNING *;
|
RETURNING *;
|
||||||
|
|
||||||
|
-- name: CleanupUpdatesNullVm :exec
|
||||||
|
DELETE FROM "Updates"
|
||||||
|
WHERE "InventoryId" IS NULL
|
||||||
|
RETURNING *;
|
||||||
|
|
||||||
-- name: CreateEvent :one
|
-- name: CreateEvent :one
|
||||||
INSERT INTO "Events" (
|
INSERT INTO "Events" (
|
||||||
"CloudId", "Source", "EventTime", "ChainId", "VmId", "VmName", "EventType", "EventKey", "DatacenterId", "DatacenterName", "ComputeResourceId", "ComputeResourceName", "UserName"
|
"CloudId", "Source", "EventTime", "ChainId", "VmId", "VmName", "EventType", "EventKey", "DatacenterId", "DatacenterName", "ComputeResourceId", "ComputeResourceName", "UserName"
|
||||||
|
@@ -26,6 +26,17 @@ func (q *Queries) CleanupUpdates(ctx context.Context, arg CleanupUpdatesParams)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cleanupUpdatesNullVm = `-- name: CleanupUpdatesNullVm :exec
|
||||||
|
DELETE FROM "Updates"
|
||||||
|
WHERE "InventoryId" IS NULL
|
||||||
|
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk, UserName, PlaceholderChange, Name
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) CleanupUpdatesNullVm(ctx context.Context) error {
|
||||||
|
_, err := q.db.ExecContext(ctx, cleanupUpdatesNullVm)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
const createEvent = `-- name: CreateEvent :one
|
const createEvent = `-- name: CreateEvent :one
|
||||||
INSERT INTO "Events" (
|
INSERT INTO "Events" (
|
||||||
"CloudId", "Source", "EventTime", "ChainId", "VmId", "VmName", "EventType", "EventKey", "DatacenterId", "DatacenterName", "ComputeResourceId", "ComputeResourceName", "UserName"
|
"CloudId", "Source", "EventTime", "ChainId", "VmId", "VmName", "EventType", "EventKey", "DatacenterId", "DatacenterName", "ComputeResourceId", "ComputeResourceName", "UserName"
|
||||||
|
@@ -2,30 +2,31 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
|
||||||
"vctp/db/queries"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// VmUpdate receives the CloudEvent for a VM modification or move
|
// VmUpdate receives the CloudEvent for a VM modification or move
|
||||||
func (h *Handler) UpdateCleanup(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) UpdateCleanup(w http.ResponseWriter, r *http.Request) {
|
||||||
// Get the current time
|
/*
|
||||||
now := time.Now()
|
// Get the current time
|
||||||
// Get the start of the current day (midnight today)
|
now := time.Now()
|
||||||
midnightToday := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
// Get the start of the current day (midnight today)
|
||||||
// Convert to Unix time
|
midnightToday := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||||
unixTime := midnightToday.Unix()
|
// Convert to Unix time
|
||||||
|
unixTime := midnightToday.Unix()
|
||||||
|
|
||||||
// create the database parameters
|
// create the database parameters
|
||||||
params := queries.CleanupUpdatesParams{
|
params := queries.CleanupUpdatesParams{
|
||||||
UpdateType: "diskchange",
|
UpdateType: "diskchange",
|
||||||
UpdateTime: sql.NullInt64{Int64: unixTime, Valid: unixTime > 0},
|
UpdateTime: sql.NullInt64{Int64: unixTime, Valid: unixTime > 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
h.Logger.Debug("database params", "params", params)
|
h.Logger.Debug("database params", "params", params)
|
||||||
err := h.Database.Queries().CleanupUpdates(context.Background(), params)
|
err := h.Database.Queries().CleanupUpdates(context.Background(), params)
|
||||||
|
*/
|
||||||
|
|
||||||
|
err := h.Database.Queries().CleanupUpdatesNullVm(context.Background())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Logger.Error("Error received cleaning updates table", "error", err)
|
h.Logger.Error("Error received cleaning updates table", "error", err)
|
||||||
|
@@ -41,7 +41,7 @@ func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver st
|
|||||||
//mux.HandleFunc("/api/inventory/vm/update", h.VmUpdateDetails)
|
//mux.HandleFunc("/api/inventory/vm/update", h.VmUpdateDetails)
|
||||||
|
|
||||||
// temporary endpoint
|
// temporary endpoint
|
||||||
//mux.HandleFunc("/api/cleanup/updates", h.UpdateCleanup)
|
mux.HandleFunc("/api/cleanup/updates", h.UpdateCleanup)
|
||||||
//mux.HandleFunc("/api/cleanup/vcenter", h.VcCleanup)
|
//mux.HandleFunc("/api/cleanup/vcenter", h.VcCleanup)
|
||||||
|
|
||||||
mux.HandleFunc("/api/report/inventory", h.InventoryReportDownload)
|
mux.HandleFunc("/api/report/inventory", h.InventoryReportDownload)
|
||||||
|
Reference in New Issue
Block a user