runtime

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRejected = errors.New("runtime: job rejected")

ErrRejected is returned by Runtime.Submit when the job was not accepted. The caller must handle cleanup by calling job.Discard(DropReasonRejected).

View Source
var ErrShutdownTimeout = errors.New("runtime: shutdown timed out")

ErrShutdownTimeout is returned when a cache close or shutdown times out.

Functions

This section is empty.

Types

type Config

type Config struct {
	Weight     int
	QueueLimit int
}

type DropReason added in v0.15.0

type DropReason int

DropReason describes why a submitted job was discarded instead of executed.

const (
	// DropReasonRejected indicates the runtime rejected the job (queue full, cache closed, etc.)
	DropReasonRejected DropReason = iota
	// DropReasonShutdown indicates the runtime was shutting down when the job was submitted or dequeued.
	DropReasonShutdown
)

type Group

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

func (*Group) CloseCache

func (r *Group) CloseCache(cacheID string, timeout time.Duration) error

func (*Group) Register

func (r *Group) Register(cacheID string, cfg Config) error

func (*Group) RemoveCache

func (r *Group) RemoveCache(cacheID string)

func (*Group) Shutdown

func (r *Group) Shutdown(timeout time.Duration) error

func (*Group) Submit

func (r *Group) Submit(cacheID string, kind JobKind, job Job) error

type Job added in v0.15.0

type Job struct {
	// Run executes the job. The context is cancelled on timeout or shutdown.
	Run func(ctx context.Context)

	// Discard is called exactly once when the job is rejected or dropped
	// during shutdown. The reason indicates why the job was not executed.
	Discard func(DropReason)
}

Job represents a unit of background work with explicit terminal semantics.

Contract: after Runtime.Submit returns nil, exactly one of Run or Discard will be called by the runtime. The caller must NOT call Run or Discard directly — they are invoked exclusively by the runtime.

Run receives a context that is cancelled when the job's deadline expires. Discard is called exactly once when the job cannot be executed.

type JobKind

type JobKind int
const (
	JobKindRefresh JobKind = iota
	JobKindPersist
)

func (JobKind) String

func (k JobKind) String() string

type Runtime

type Runtime interface {
	Register(cacheID string, cfg Config) error
	Submit(cacheID string, kind JobKind, job Job) error
	CloseCache(cacheID string, timeout time.Duration) error
	RemoveCache(cacheID string)
	Shutdown(timeout time.Duration) error
}

Runtime manages background jobs for one or more caches.

Submit enqueues a job. On success (nil error returned), the runtime guarantees that exactly one of job.Run or job.Discard will be called. On error, the caller must handle cleanup themselves (typically by calling job.Discard(reason)).

func NewGroup

func NewGroup(logger log.Logger, workers int, timeout time.Duration) Runtime

func NewStandalone

func NewStandalone(manager *worker.Manager) Runtime

type Standalone

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

func (*Standalone) CloseCache

func (r *Standalone) CloseCache(_ string, timeout time.Duration) error

func (*Standalone) Register

func (r *Standalone) Register(string, Config) error

func (*Standalone) RemoveCache

func (r *Standalone) RemoveCache(_ string)

func (*Standalone) Shutdown

func (r *Standalone) Shutdown(timeout time.Duration) error

func (*Standalone) Submit

func (r *Standalone) Submit(_ string, _ JobKind, job Job) error

Jump to

Keyboard shortcuts

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