2026-04-06 15:48:37 +05:30
|
|
|
// Copyright IBM Corp. 2020, 2026
|
2025-01-09 10:26:37 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
|
|
package server
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2026-10-12 10:33:41 -07:00
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
2025-01-09 10:26:37 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// UpsertSessionInfo will update the session info latest request time to the current time for the given worker.
|
|
|
|
|
func (r *Repository) UpsertSessionInfo(ctx context.Context, workerId string, _ ...Option) error {
|
|
|
|
|
const op = "server.(Repository).UpsertSessionInfo"
|
|
|
|
|
if workerId == "" {
|
|
|
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing worker id")
|
|
|
|
|
}
|
|
|
|
|
sessionInfo := NewWorkerSessionInfoRequest(workerId)
|
|
|
|
|
_, err := r.writer.DoTx(
|
|
|
|
|
ctx,
|
|
|
|
|
db.StdRetryCnt,
|
|
|
|
|
db.ExpBackoff{},
|
|
|
|
|
func(_ db.Reader, w db.Writer) error {
|
|
|
|
|
upsert := db.WithOnConflict(&db.OnConflict{
|
|
|
|
|
Target: db.Columns{"worker_id"},
|
|
|
|
|
Action: db.SetColumns([]string{"last_request_time"}),
|
|
|
|
|
})
|
|
|
|
|
return w.Create(ctx, sessionInfo, upsert)
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return errors.Wrap(ctx, err, op, errors.WithMsg(fmt.Sprintf("failed for %s", workerId)))
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|