From e14a58d5c13b8614264ef2525fd8c76ecd39daa4 Mon Sep 17 00:00:00 2001 From: marco Date: Tue, 30 Apr 2024 14:44:53 +0200 Subject: [PATCH] update last_push in CreateAlert() --- pkg/database/alerts.go | 7 +++++++ pkg/database/machines.go | 8 -------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/database/alerts.go b/pkg/database/alerts.go index 5559cbb39..c3957d31c 100644 --- a/pkg/database/alerts.go +++ b/pkg/database/alerts.go @@ -795,6 +795,13 @@ func (c *Client) CreateAlert(machineID string, alertList []*models.Alert) ([]str alertIDs = append(alertIDs, ids...) } + if owner != nil { + err = owner.Update().SetLastPush(time.Now().UTC()).Exec(c.CTX) + if err != nil { + return nil, fmt.Errorf("machine '%s': %w", machineID, err) + } + } + return alertIDs, nil } diff --git a/pkg/database/machines.go b/pkg/database/machines.go index b9834e57e..7a64c1d4d 100644 --- a/pkg/database/machines.go +++ b/pkg/database/machines.go @@ -134,14 +134,6 @@ func (c *Client) BulkDeleteWatchers(machines []*ent.Machine) (int, error) { return nbDeleted, nil } -func (c *Client) UpdateMachineLastPush(machineID string) error { - _, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(machineID)).SetLastPush(time.Now().UTC()).Save(c.CTX) - if err != nil { - return errors.Wrapf(UpdateFail, "updating machine last_push: %s", err) - } - return nil -} - func (c *Client) UpdateMachineLastHeartBeat(machineID string) error { _, err := c.Ent.Machine.Update().Where(machine.MachineIdEQ(machineID)).SetLastHeartbeat(time.Now().UTC()).Save(c.CTX) if err != nil {