Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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).
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 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) RemoveCache ¶
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 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 NewStandalone ¶
type Standalone ¶
type Standalone struct {
// contains filtered or unexported fields
}
func (*Standalone) CloseCache ¶
func (r *Standalone) CloseCache(_ string, timeout time.Duration) error
func (*Standalone) RemoveCache ¶
func (r *Standalone) RemoveCache(_ string)