Documentation
¶
Index ¶
- Variables
- type JobOutcome
- type JobSpec
- type ManagedConfig
- type ManagedPool
- type ManagedSnapshot
- type QueuedConfig
- type QueuedPool
- func (p *QueuedPool) Pending() int
- func (p *QueuedPool) QueueSize() int
- func (p *QueuedPool) StopAndWait()
- func (p *QueuedPool) StopAndWaitContext(ctx context.Context) error
- func (p *QueuedPool) SubmitWait(task func()) bool
- func (p *QueuedPool) TrySubmit(task func()) bool
- func (p *QueuedPool) Workers() int
Constants ¶
This section is empty.
Variables ¶
var ErrJobTimeout = errors.New("managed worker job timeout")
ErrJobTimeout은 dequeue 이후 job budget이 소진된 원인이다.
var ErrPoolShutdown = errors.New("managed worker pool shutdown")
ErrPoolShutdown은 pool shutdown으로 in-flight job이 취소된 원인이다.
Functions ¶
This section is empty.
Types ¶
type JobOutcome ¶ added in v1.29.0
type JobOutcome string
JobOutcome은 managed job이 종료된 이유를 나타낸다.
const ( JobOutcomeSuccess JobOutcome = "success" JobOutcomeRejected JobOutcome = "rejected" JobOutcomeStale JobOutcome = "stale" JobOutcomePanic JobOutcome = "panic" JobOutcomeShutdown JobOutcome = "shutdown" JobOutcomeTimeout JobOutcome = "timeout" JobOutcomeCanceled JobOutcome = "canceled" )
type JobSpec ¶ added in v1.29.0
type JobSpec struct {
Context context.Context
Kind string
Timeout time.Duration
MaxQueueAge time.Duration
Run func(context.Context)
Finalize func(context.Context, JobOutcome)
}
JobSpec은 queue admission 이후 dequeue 시점에 실행 budget을 만드는 작업 계약이다.
type ManagedConfig ¶ added in v1.29.0
type ManagedConfig struct {
Workers int
QueueSize int
FinalizeTimeout time.Duration
Logger *slog.Logger
}
ManagedConfig는 ManagedPool의 고정 worker, queue, cleanup budget을 설정한다.
type ManagedPool ¶ added in v1.29.0
type ManagedPool struct {
// contains filtered or unexported fields
}
ManagedPool은 dequeue-time budget과 단일 finalization을 소유하는 worker pool이다.
func NewManaged ¶ added in v1.29.0
func NewManaged(config ManagedConfig) *ManagedPool
NewManaged는 immutable worker와 queue 크기로 ManagedPool을 시작한다.
func (*ManagedPool) CloseContext ¶ added in v1.29.0
func (p *ManagedPool) CloseContext(ctx context.Context) error
CloseContext는 admission을 닫고 queued job을 drop하며 in-flight job을 취소한다.
func (*ManagedPool) Snapshot ¶ added in v1.29.0
func (p *ManagedPool) Snapshot() ManagedSnapshot
Snapshot은 호출 시점의 queue depth, in-flight, oldest queue age, outcome 누계를 반환한다.
func (*ManagedPool) TrySubmit ¶ added in v1.29.0
func (p *ManagedPool) TrySubmit(spec JobSpec) bool
TrySubmit은 작업을 기다리지 않고 queue에 admission한다.
type ManagedSnapshot ¶ added in v1.29.0
type ManagedSnapshot struct {
QueueDepth int
InFlight int
OldestQueueAge time.Duration
Outcomes map[JobOutcome]uint64
}
ManagedSnapshot은 pool의 현재 queue, 실행, outcome 상태를 복사해 제공한다.
type QueuedConfig ¶
type QueuedPool ¶
type QueuedPool struct {
// contains filtered or unexported fields
}
func NewQueued ¶
func NewQueued(config QueuedConfig) *QueuedPool
func NewQueuedWithLogger ¶
func NewQueuedWithLogger(config QueuedConfig, logger *slog.Logger) *QueuedPool
NewQueuedWithLogger는 panic recover 로그에 사용할 logger를 주입한다. logger가 nil이면 slog.Default()를 사용한다.
func (*QueuedPool) Pending ¶
func (p *QueuedPool) Pending() int
func (*QueuedPool) QueueSize ¶
func (p *QueuedPool) QueueSize() int
func (*QueuedPool) StopAndWait ¶
func (p *QueuedPool) StopAndWait()
func (*QueuedPool) StopAndWaitContext ¶
func (p *QueuedPool) StopAndWaitContext(ctx context.Context) error
func (*QueuedPool) SubmitWait ¶
func (p *QueuedPool) SubmitWait(task func()) bool
func (*QueuedPool) TrySubmit ¶
func (p *QueuedPool) TrySubmit(task func()) bool
func (*QueuedPool) Workers ¶
func (p *QueuedPool) Workers() int