runners

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPRunner

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

HTTPRunner wraps an *http.Server as a Runner. The caller is responsible for configuring the server (timeouts, handler, TLS).

func NewHTTPRunner

func NewHTTPRunner(name string, server *http.Server, log *slog.Logger) *HTTPRunner

NewHTTPRunner creates a plain HTTP runner.

func NewHTTPSRunner

func NewHTTPSRunner(name string, server *http.Server, certFile, keyFile string, log *slog.Logger) *HTTPRunner

NewHTTPSRunner creates a TLS HTTP runner.

func (*HTTPRunner) Name

func (r *HTTPRunner) Name() string

func (*HTTPRunner) Start

func (r *HTTPRunner) Start(ctx context.Context) error

func (*HTTPRunner) Stop

func (r *HTTPRunner) Stop(ctx context.Context) error

type JobFn

type JobFn func(ctx context.Context) error

JobFn is a periodic task. Errors are logged and the scheduler continues. To stop on error, return a wrapped sentinel and check it in an outer WorkerRunner.

type SchedulerRunner

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

SchedulerRunner executes a JobFn on a fixed interval using time.Ticker. Missed ticks (slow jobs) are dropped — no queue buildup.

func NewSchedulerRunner

func NewSchedulerRunner(name string, interval time.Duration, fn JobFn, log *slog.Logger) *SchedulerRunner

func (*SchedulerRunner) Name

func (r *SchedulerRunner) Name() string

func (*SchedulerRunner) Start

func (r *SchedulerRunner) Start(ctx context.Context) error

func (*SchedulerRunner) Stop

func (r *SchedulerRunner) Stop(ctx context.Context) error

Stop is a no-op: ctx cancellation in Start handles shutdown.

type WorkFn

type WorkFn func(ctx context.Context) error

WorkFn is the unit of work executed each iteration. Return an error to trigger the onError callback. Return ctx.Err() (or nil) to stop cleanly.

type WorkerOption

type WorkerOption func(*WorkerRunner)

func WithErrorHandler

func WithErrorHandler(fn func(err error)) WorkerOption

WithErrorHandler overrides the default log-and-continue error handler. To make errors fatal (stop the worker), call the provided cancel func.

type WorkerRunner

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

WorkerRunner executes a WorkFn in a tight loop until ctx is cancelled. It does NOT restart after failure — if you need retry, implement it inside WorkFn.

func NewWorkerRunner

func NewWorkerRunner(name string, fn WorkFn, log *slog.Logger, opts ...WorkerOption) *WorkerRunner

func (*WorkerRunner) Name

func (r *WorkerRunner) Name() string

func (*WorkerRunner) Start

func (r *WorkerRunner) Start(ctx context.Context) error

func (*WorkerRunner) Stop

func (r *WorkerRunner) Stop(ctx context.Context) error

Stop is a no-op: ctx cancellation in Start handles shutdown.

Jump to

Keyboard shortcuts

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