62886dbba8
Remove Job * removejob * rmjob * sync * cleanup * precommit * startslow * startslow * startslow * openapi * clean * test * scripts * littlecleanercmds * mermaid
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package clientsyncrunner
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"log/slog"
|
|
|
|
clientsync "queryorchestration/internal/client/sync"
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
|
)
|
|
|
|
const Name = "clientSyncRunner"
|
|
|
|
type Services struct {
|
|
ClientSync *clientsync.Service
|
|
}
|
|
|
|
type Runner struct {
|
|
validator *validator.Validate
|
|
svc *Services
|
|
}
|
|
|
|
func New(validator *validator.Validate, svc *Services) Runner {
|
|
return Runner{
|
|
validator: validator,
|
|
svc: svc,
|
|
}
|
|
}
|
|
|
|
type Body struct {
|
|
ID uuid.UUID `json:"id" validate:"required,uuid"`
|
|
}
|
|
|
|
func (s *Runner) Process(ctx context.Context, req *types.Message) bool {
|
|
var body Body
|
|
err := json.Unmarshal([]byte(*req.Body), &body)
|
|
if err != nil {
|
|
slog.Error("parsing body", "messageId", *req.MessageId, "body", *req.Body)
|
|
return true
|
|
}
|
|
|
|
err = s.validator.Struct(body)
|
|
if err != nil {
|
|
slog.Error("invalid body", "messageId", *req.MessageId, "error", err)
|
|
return true
|
|
}
|
|
|
|
err = s.svc.ClientSync.Sync(ctx, body.ID)
|
|
if err != nil {
|
|
slog.Error("unable to process", "error", err)
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|