scheduler

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidJob is returned when a job fails validation.
	ErrInvalidJob = errors.New("invalid job")
	// ErrUnsupportedMethod is returned for unsupported HTTP methods.
	ErrUnsupportedMethod = errors.New("unsupported method")
	// ErrRetryableStatus marks responses that should be retried.
	ErrRetryableStatus = errors.New("retryable status")
)

Functions

This section is empty.

Types

type Callback

type Callback struct {
	URL          string
	Method       string
	Headers      map[string]string
	Timeout      time.Duration
	MaxBodyBytes int
}

Callback describes where to send execution results.

type CallbackPayload

type CallbackPayload struct {
	JobID        string    `json:"job_id"`
	ScheduledAt  time.Time `json:"scheduled_at"`
	StartedAt    time.Time `json:"started_at"`
	FinishedAt   time.Time `json:"finished_at"`
	Attempts     int       `json:"attempts"`
	Success      bool      `json:"success"`
	StatusCode   int       `json:"status_code,omitempty"`
	Error        string    `json:"error,omitempty"`
	ResponseBody string    `json:"response_body,omitempty"`
}

CallbackPayload is posted to the callback endpoint after each execution.

type Job

type Job struct {
	ID          string
	Schedule    Schedule
	Request     Request
	Callback    Callback
	RetryPolicy RetryPolicy
}

Job defines the schedule and behavior for a task.

type Option

type Option func(*Scheduler)

Option configures the scheduler.

func WithConcurrency

func WithConcurrency(n int) Option

WithConcurrency limits the number of concurrent executions.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets the HTTP client used for requests and callbacks.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the scheduler logger.

func WithURLValidator added in v1.2.2

func WithURLValidator(validator *validate.URLValidator) Option

WithURLValidator sets the URL validator used for request and callback URLs. Pass nil to disable URL validation.

type Request

type Request struct {
	Method  string
	URL     string
	Headers map[string]string
	Body    []byte
	Timeout time.Duration
}

Request describes the target HTTP request.

type RetryPolicy

type RetryPolicy struct {
	Retrier          *again.Retrier
	TemporaryErrors  []error
	RetryStatusCodes []int
}

RetryPolicy defines how retries should be performed.

type Schedule

type Schedule struct {
	Every   time.Duration
	StartAt time.Time
	EndAt   time.Time
	MaxRuns int
}

Schedule defines when a job should run.

type Scheduler

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

Scheduler coordinates scheduled jobs.

func NewScheduler

func NewScheduler(opts ...Option) *Scheduler

NewScheduler creates a scheduler with the provided options.

func (*Scheduler) Remove

func (s *Scheduler) Remove(id string) bool

Remove stops a scheduled job.

func (*Scheduler) Schedule

func (s *Scheduler) Schedule(job Job) (string, error)

Schedule registers a job and starts its schedule loop.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop cancels all jobs and waits for completion.

type StatusError

type StatusError struct {
	StatusCode int
}

StatusError reports a non-successful response status.

func (*StatusError) Error

func (e *StatusError) Error() string

Jump to

Keyboard shortcuts

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