chore: add asynchronous webhook dispatch

pull/4717/head
Steven 2 months ago
parent 7c05a9b997
commit f12d7ae8bc

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"io"
"log/slog"
"net/http"
"time"
@ -63,3 +64,17 @@ func Post(requestPayload *v1pb.WebhookRequestPayload) error {
return nil
}
// PostAsync posts the message to webhook endpoint asynchronously.
// It spawns a new goroutine to handle the request and does not wait for the response.
func PostAsync(requestPayload *v1pb.WebhookRequestPayload) {
go func() {
if err := Post(requestPayload); err != nil {
// Since we're in a goroutine, we can only log the error
slog.Warn("Failed to dispatch webhook asynchronously",
slog.String("url", requestPayload.Url),
slog.String("activityType", requestPayload.ActivityType),
slog.Any("err", err))
}
}()
}

@ -689,9 +689,9 @@ func (s *APIV1Service) dispatchMemoRelatedWebhook(ctx context.Context, memo *v1p
}
payload.ActivityType = activityType
payload.Url = hook.URL
if err := webhook.Post(payload); err != nil {
return errors.Wrap(err, "failed to post webhook")
}
// Use asynchronous webhook dispatch
webhook.PostAsync(payload)
}
return nil
}

Loading…
Cancel
Save