api

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package api provides HTTP handlers for GopherQueue.

Package api provides the HTTP API server for GopherQueue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchSubmitJobResult added in v1.1.0

type BatchSubmitJobResult struct {
	Index   int         `json:"index"`
	Success bool        `json:"success"`
	Job     JobResponse `json:"job,omitempty"`
	Error   string      `json:"error,omitempty"`
}

BatchSubmitJobResult is the result for a single job in batch submission.

type BatchSubmitRequest added in v1.1.0

type BatchSubmitRequest struct {
	Jobs   []JobSubmitRequest `json:"jobs"`
	Atomic bool               `json:"atomic"` // All-or-nothing semantics
}

BatchSubmitRequest is the request body for batch job submission.

type BatchSubmitResponse added in v1.1.0

type BatchSubmitResponse struct {
	Total    int                    `json:"total"`
	Accepted int                    `json:"accepted"`
	Rejected int                    `json:"rejected"`
	Results  []BatchSubmitJobResult `json:"results"`
}

BatchSubmitResponse is the response for batch job submission.

type EventBus added in v1.1.0

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

EventBus manages SSE subscriptions for real-time job updates.

func NewEventBus added in v1.1.0

func NewEventBus() *EventBus

NewEventBus creates a new event bus.

func (*EventBus) Publish added in v1.1.0

func (eb *EventBus) Publish(jobID string, event SSEEvent)

Publish sends an event to all subscribers.

func (*EventBus) Subscribe added in v1.1.0

func (eb *EventBus) Subscribe(jobID string) chan SSEEvent

Subscribe subscribes to events for a specific job or all jobs.

func (*EventBus) Unsubscribe added in v1.1.0

func (eb *EventBus) Unsubscribe(jobID string, ch chan SSEEvent)

Unsubscribe removes a subscription.

type JobResponse

type JobResponse struct {
	ID              string            `json:"id"`
	Type            string            `json:"type"`
	State           string            `json:"state"`
	Priority        int               `json:"priority"`
	Attempt         int               `json:"attempt"`
	MaxAttempts     int               `json:"max_attempts"`
	Progress        float64           `json:"progress,omitempty"`
	ProgressMessage string            `json:"progress_message,omitempty"`
	Tags            map[string]string `json:"tags,omitempty"`
	CreatedAt       time.Time         `json:"created_at"`
	UpdatedAt       time.Time         `json:"updated_at"`
	ScheduledAt     *time.Time        `json:"scheduled_at,omitempty"`
	StartedAt       *time.Time        `json:"started_at,omitempty"`
	CompletedAt     *time.Time        `json:"completed_at,omitempty"`
	LastError       string            `json:"last_error,omitempty"`
}

JobResponse is the response for job operations.

type JobSubmitRequest

type JobSubmitRequest struct {
	Type           string            `json:"type"`
	Payload        json.RawMessage   `json:"payload"`
	Priority       *int              `json:"priority,omitempty"`
	IdempotencyKey string            `json:"idempotency_key,omitempty"`
	CorrelationID  string            `json:"correlation_id,omitempty"`
	Delay          string            `json:"delay,omitempty"`
	ScheduledAt    *time.Time        `json:"scheduled_at,omitempty"`
	Timeout        string            `json:"timeout,omitempty"`
	MaxAttempts    *int              `json:"max_attempts,omitempty"`
	Tags           map[string]string `json:"tags,omitempty"`
}

JobSubmitRequest is the request body for job submission.

type SSEEvent added in v1.1.0

type SSEEvent struct {
	Event string      `json:"event"`
	Data  interface{} `json:"data"`
	ID    string      `json:"id,omitempty"`
}

SSEEvent represents a Server-Sent Event.

type Server

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

Server is the HTTP API server.

func NewServer

func NewServer(
	store persistence.JobStore,
	sched scheduler.Scheduler,
	pool worker.WorkerPool,
	config *ServerConfig,
) *Server

NewServer creates a new API server.

func (*Server) GetEventBus added in v1.1.0

func (s *Server) GetEventBus() *EventBus

GetEventBus returns the event bus for publishing events.

func (*Server) SetAuthenticator

func (s *Server) SetAuthenticator(auth security.Authenticator)

SetAuthenticator sets the authenticator.

func (*Server) Start

func (s *Server) Start() error

Start starts the HTTP server.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully shuts down the server.

type ServerConfig

type ServerConfig struct {
	Addr           string
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	MaxRequestSize int64
	AuthEnabled    bool
	CORSEnabled    bool
	CORSOrigins    []string
}

ServerConfig configures the API server.

func DefaultServerConfig

func DefaultServerConfig() *ServerConfig

DefaultServerConfig returns sensible defaults.

type StatsResponse

type StatsResponse struct {
	Queue   *persistence.QueueStats `json:"queue"`
	Workers interface{}             `json:"workers"`
}

StatsResponse is the response for statistics.

type WaitRequest added in v1.1.0

type WaitRequest struct {
	Timeout string `json:"timeout"` // e.g., "30s"
}

WaitRequest is the request body for waiting on a job.

type WaitResponse added in v1.1.0

type WaitResponse struct {
	ID        string          `json:"id"`
	State     string          `json:"state"`
	Completed bool            `json:"completed"`
	Success   bool            `json:"success,omitempty"`
	Result    *core.JobResult `json:"result,omitempty"`
	TimedOut  bool            `json:"timed_out,omitempty"`
}

WaitResponse is the response for waiting on a job.

Jump to

Keyboard shortcuts

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