webhooks

package
v0.3.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package webhooks provides HTTP webhook notification system for task events

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifySignature

func VerifySignature(payload []byte, signature, secret string) bool

VerifySignature verifies an HMAC signature

Types

type DeliveryResult

type DeliveryResult struct {
	WebhookID  string
	DeliveryID string
	Event      EventType
	StatusCode int
	Success    bool
	Error      string
	DurationMS int64
	Timestamp  int64
}

DeliveryResult represents the result of a webhook delivery attempt

type DeliveryTask

type DeliveryTask struct {
	// contains filtered or unexported fields
}

DeliveryTask represents a webhook delivery task

type EventType

type EventType string

EventType represents the type of event that triggered the webhook

const (
	EventTaskCreated   EventType = "task.created"
	EventTaskClaimed   EventType = "task.claimed"
	EventTaskStarted   EventType = "task.started"
	EventTaskPaused    EventType = "task.paused"
	EventTaskResumed   EventType = "task.resumed"
	EventTaskBlocked   EventType = "task.blocked"
	EventTaskCompleted EventType = "task.completed"
	EventTaskFailed    EventType = "task.failed"
	EventWorkerStarted EventType = "worker.started"
	EventWorkerStopped EventType = "worker.stopped"
)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages webhook registration and delivery

func NewManager

func NewManager() *Manager

NewManager creates a new webhook manager

func (*Manager) Disable

func (m *Manager) Disable(id string) error

Disable disables a webhook

func (*Manager) Emit

func (m *Manager) Emit(event EventType, data map[string]interface{})

Emit sends an event to all subscribed webhooks

func (*Manager) EmitTaskBlocked

func (m *Manager) EmitTaskBlocked(taskID, title string)

EmitTaskBlocked emits a task blocked event

func (*Manager) EmitTaskClaimed

func (m *Manager) EmitTaskClaimed(taskID, title, workerID string)

EmitTaskClaimed emits a task claimed event

func (*Manager) EmitTaskCompleted

func (m *Manager) EmitTaskCompleted(taskID, title string, durationMS int64)

EmitTaskCompleted emits a task completed event

func (*Manager) EmitTaskCreated

func (m *Manager) EmitTaskCreated(taskID, title, epicID string)

EmitTaskCreated emits a task created event

func (*Manager) EmitTaskFailed

func (m *Manager) EmitTaskFailed(taskID, title, errorMsg string, attempts int)

EmitTaskFailed emits a task failed event

func (*Manager) EmitTaskPaused

func (m *Manager) EmitTaskPaused(taskID, title string)

EmitTaskPaused emits a task paused event

func (*Manager) EmitTaskResumed

func (m *Manager) EmitTaskResumed(taskID, title string)

EmitTaskResumed emits a task resumed event

func (*Manager) EmitTaskStarted

func (m *Manager) EmitTaskStarted(taskID, title, workerID string)

EmitTaskStarted emits a task started event

func (*Manager) EmitWorkerStarted

func (m *Manager) EmitWorkerStarted(workerID string, workerIndex int)

EmitWorkerStarted emits a worker started event

func (*Manager) EmitWorkerStopped

func (m *Manager) EmitWorkerStopped(workerID string, workerIndex, taskCount int)

EmitWorkerStopped emits a worker stopped event

func (*Manager) Enable

func (m *Manager) Enable(id string) error

Enable enables a webhook

func (*Manager) Get

func (m *Manager) Get(id string) (*Webhook, error)

Get retrieves a webhook by ID

func (*Manager) GetDeliveryHistory

func (m *Manager) GetDeliveryHistory(limit int) []*DeliveryResult

GetDeliveryHistory returns recent delivery results

func (*Manager) List

func (m *Manager) List() []*Webhook

List returns all registered webhooks

func (*Manager) Register

func (m *Manager) Register(webhook *Webhook) error

Register registers a new webhook

func (*Manager) SetLogger

func (m *Manager) SetLogger(logger *log.Logger)

SetLogger sets the logger for the webhook manager

func (*Manager) SetTimeout

func (m *Manager) SetTimeout(timeout time.Duration)

SetTimeout sets the HTTP client timeout

func (*Manager) Start

func (m *Manager) Start(workers int)

Start begins processing webhook deliveries

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context) error

Stop gracefully shuts down the webhook manager

func (*Manager) Unregister

func (m *Manager) Unregister(id string) error

Unregister removes a webhook

type Payload

type Payload struct {
	Event      EventType              `json:"event"`
	Timestamp  int64                  `json:"timestamp"`
	WebhookID  string                 `json:"webhook_id"`
	DeliveryID string                 `json:"delivery_id"` // Unique ID for each delivery attempt
	Data       map[string]interface{} `json:"data"`
}

Payload represents the webhook payload sent to endpoints

type TaskEventData

type TaskEventData struct {
	TaskID     string `json:"task_id"`
	Title      string `json:"title"`
	EpicID     string `json:"epic_id,omitempty"`
	Status     string `json:"status"`
	WorkerID   string `json:"worker_id,omitempty"`
	Error      string `json:"error,omitempty"`
	Attempts   int    `json:"attempts,omitempty"`
	DurationMS int64  `json:"duration_ms,omitempty"`
}

TaskEventData contains task-related event data

type Webhook

type Webhook struct {
	ID        string            `json:"id"`
	URL       string            `json:"url"`
	Secret    string            `json:"secret,omitempty"` // HMAC secret for verification
	Events    []EventType       `json:"events"`           // Events to subscribe to
	Headers   map[string]string `json:"headers,omitempty"`
	Enabled   bool              `json:"enabled"`
	CreatedAt int64             `json:"created_at"`
}

Webhook represents a configured webhook endpoint

type WorkerEventData

type WorkerEventData struct {
	WorkerID    string `json:"worker_id"`
	WorkerIndex int    `json:"worker_index"`
	TaskCount   int    `json:"task_count"`
}

WorkerEventData contains worker-related event data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL