diff --git a/pkg/coredata/migrations/20260210T135740Z.sql b/pkg/coredata/migrations/20260210T135740Z.sql index e2a9bb96b..8bbbd0743 100644 --- a/pkg/coredata/migrations/20260210T135740Z.sql +++ b/pkg/coredata/migrations/20260210T135740Z.sql @@ -21,7 +21,8 @@ CREATE TABLE webhook_configurations ( CREATE TYPE webhook_data_status AS ENUM ( 'PENDING', 'PROCESSING', - 'DELIVERED' + 'PROCESSED', + 'FAILED' ); CREATE TABLE webhook_data ( diff --git a/pkg/coredata/webhook_data_status.go b/pkg/coredata/webhook_data_status.go index 10662edc6..f0705443a 100644 --- a/pkg/coredata/webhook_data_status.go +++ b/pkg/coredata/webhook_data_status.go @@ -24,7 +24,8 @@ type WebhookDataStatus string const ( WebhookDataStatusPending WebhookDataStatus = "PENDING" WebhookDataStatusProcessing WebhookDataStatus = "PROCESSING" - WebhookDataStatusDelivered WebhookDataStatus = "DELIVERED" + WebhookDataStatusProcessed WebhookDataStatus = "PROCESSED" + WebhookDataStatusFailed WebhookDataStatus = "FAILED" ) func (s WebhookDataStatus) String() string { @@ -33,7 +34,7 @@ func (s WebhookDataStatus) String() string { func (s WebhookDataStatus) IsValid() bool { switch s { - case WebhookDataStatusPending, WebhookDataStatusProcessing, WebhookDataStatusDelivered: + case WebhookDataStatusPending, WebhookDataStatusProcessing, WebhookDataStatusProcessed, WebhookDataStatusFailed: return true } return false diff --git a/pkg/webhook/sender.go b/pkg/webhook/sender.go index 93d9d7845..908ff455b 100644 --- a/pkg/webhook/sender.go +++ b/pkg/webhook/sender.go @@ -148,6 +148,7 @@ func (s *Sender) processWebhookData(ctx context.Context, webhookData *coredata.W log.Error(err), log.String("webhook_data_id", webhookData.ID.String()), ) + s.markWebhookData(ctx, webhookData, scope, coredata.WebhookDataStatusFailed) return } @@ -155,17 +156,22 @@ func (s *Sender) processWebhookData(ctx context.Context, webhookData *coredata.W s.deliverToConfiguration(ctx, webhookData, config, scope) } + s.markWebhookData(ctx, webhookData, scope, coredata.WebhookDataStatusProcessed) +} + +func (s *Sender) markWebhookData(ctx context.Context, webhookData *coredata.WebhookData, scope coredata.Scoper, status coredata.WebhookDataStatus) { now := time.Now() - webhookData.Status = coredata.WebhookDataStatusDelivered + webhookData.Status = status webhookData.ProcessedAt = &now - err = s.pg.WithConn(ctx, func(conn pg.Conn) error { + err := s.pg.WithConn(ctx, func(conn pg.Conn) error { return webhookData.UpdateStatus(ctx, conn, scope) }) if err != nil { - s.logger.ErrorCtx(ctx, "cannot update webhook data to delivered", + s.logger.ErrorCtx(ctx, "cannot update webhook data status", log.Error(err), log.String("webhook_data_id", webhookData.ID.String()), + log.String("target_status", status.String()), ) } }