Documentation
¶
Index ¶
- type EventConfig
- type TriggerService
- type Webhook
- type WebhookDelivery
- type WebhookEvent
- type WebhookPayload
- type WebhookService
- func (s *WebhookService) Create(ctx context.Context, webhook *Webhook) error
- func (s *WebhookService) Delete(ctx context.Context, id uuid.UUID) error
- func (s *WebhookService) Deliver(ctx context.Context, webhook *Webhook, payload *WebhookPayload) error
- func (s *WebhookService) Get(ctx context.Context, id uuid.UUID) (*Webhook, error)
- func (s *WebhookService) List(ctx context.Context) ([]*Webhook, error)
- func (s *WebhookService) ListDeliveries(ctx context.Context, webhookID uuid.UUID, limit int) ([]*WebhookDelivery, error)
- func (s *WebhookService) Update(ctx context.Context, id uuid.UUID, webhook *Webhook) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventConfig ¶
type EventConfig struct {
Table string `json:"table"` // e.g., "products", "users"
Operations []string `json:"operations"` // INSERT, UPDATE, DELETE
}
EventConfig represents events a webhook subscribes to
type TriggerService ¶
type TriggerService struct {
// contains filtered or unexported fields
}
TriggerService manages webhook event processing
func NewTriggerService ¶
func NewTriggerService(db *pgxpool.Pool, webhookSvc *WebhookService, workers int) *TriggerService
NewTriggerService creates a new webhook trigger service
func (*TriggerService) SetBacklogInterval ¶
func (s *TriggerService) SetBacklogInterval(interval time.Duration)
SetBacklogInterval allows customizing the backlog check interval (useful for testing) If the service is already running, it will reset the ticker with the new interval
func (*TriggerService) Start ¶
func (s *TriggerService) Start(ctx context.Context) error
Start begins processing webhook events
func (*TriggerService) Stop ¶
func (s *TriggerService) Stop()
Stop gracefully stops the trigger service
type Webhook ¶
type Webhook struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
URL string `json:"url"`
Secret *string `json:"secret,omitempty"`
Enabled bool `json:"enabled"`
Events []EventConfig `json:"events"`
MaxRetries int `json:"max_retries"`
RetryBackoffSeconds int `json:"retry_backoff_seconds"`
TimeoutSeconds int `json:"timeout_seconds"`
Headers map[string]string `json:"headers"`
CreatedBy *uuid.UUID `json:"created_by,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Webhook represents a webhook configuration
type WebhookDelivery ¶
type WebhookDelivery struct {
ID uuid.UUID `json:"id"`
WebhookID uuid.UUID `json:"webhook_id"`
EventType string `json:"event_type"`
TableName string `json:"table_name"`
RecordID *string `json:"record_id,omitempty"`
Payload json.RawMessage `json:"payload"`
AttemptNumber int `json:"attempt_number"`
Status string `json:"status"` // pending, success, failed, retrying
HTTPStatusCode *int `json:"http_status_code,omitempty"`
ResponseBody *string `json:"response_body,omitempty"`
ErrorMessage *string `json:"error_message,omitempty"`
CreatedAt time.Time `json:"created_at"`
DeliveredAt *time.Time `json:"delivered_at,omitempty"`
NextRetryAt *time.Time `json:"next_retry_at,omitempty"`
}
WebhookDelivery represents a webhook delivery attempt
type WebhookEvent ¶
type WebhookEvent struct {
ID uuid.UUID `db:"id"`
WebhookID uuid.UUID `db:"webhook_id"`
EventType string `db:"event_type"`
TableSchema string `db:"table_schema"`
TableName string `db:"table_name"`
RecordID *string `db:"record_id"`
OldData json.RawMessage `db:"old_data"`
NewData json.RawMessage `db:"new_data"`
Processed bool `db:"processed"`
Attempts int `db:"attempts"`
LastAttemptAt *time.Time `db:"last_attempt_at"`
NextRetryAt *time.Time `db:"next_retry_at"`
ErrorMessage *string `db:"error_message"`
CreatedAt time.Time `db:"created_at"`
}
WebhookEvent represents an event waiting to be delivered
type WebhookPayload ¶
type WebhookPayload struct {
Event string `json:"event"` // INSERT, UPDATE, DELETE
Table string `json:"table"` // table name
Schema string `json:"schema"` // schema name
Record json.RawMessage `json:"record"` // new record data
OldRecord json.RawMessage `json:"old_record,omitempty"` // old record (for UPDATE/DELETE)
Timestamp time.Time `json:"timestamp"`
}
WebhookPayload represents the payload sent to webhooks
type WebhookService ¶
type WebhookService struct {
// contains filtered or unexported fields
}
WebhookService manages webhooks
func NewWebhookService ¶
func NewWebhookService(db *pgxpool.Pool) *WebhookService
NewWebhookService creates a new webhook service
func (*WebhookService) Create ¶
func (s *WebhookService) Create(ctx context.Context, webhook *Webhook) error
Create creates a new webhook
func (*WebhookService) Deliver ¶
func (s *WebhookService) Deliver(ctx context.Context, webhook *Webhook, payload *WebhookPayload) error
Deliver sends a webhook payload to the configured URL
func (*WebhookService) List ¶
func (s *WebhookService) List(ctx context.Context) ([]*Webhook, error)
List lists all webhooks
func (*WebhookService) ListDeliveries ¶
func (s *WebhookService) ListDeliveries(ctx context.Context, webhookID uuid.UUID, limit int) ([]*WebhookDelivery, error)
ListDeliveries lists webhook deliveries