Documentation
¶
Index ¶
- Variables
- type Job
- type ListInput
- type OptionStore
- type Overview
- type PostgresOptionStore
- type Queue
- type Schedule
- type ScheduleConstructor
- type Service
- func (s *Service) Cancel(ctx context.Context, actor identity.Actor, id int64) (Job, error)
- func (s *Service) Detail(ctx context.Context, actor identity.Actor, id int64) (Job, error)
- func (s *Service) List(ctx context.Context, actor identity.Actor, input ListInput) ([]Job, error)
- func (s *Service) Overview(ctx context.Context, actor identity.Actor) (Overview, error)
- func (s *Service) Retry(ctx context.Context, actor identity.Actor, id int64) (Job, error)
- func (s *Service) Schedules(ctx context.Context, actor identity.Actor) ([]Schedule, error)
- func (s *Service) SetQueuePaused(ctx context.Context, actor identity.Actor, name string, paused bool) error
- func (s *Service) SetScheduleEnabled(ctx context.Context, actor identity.Actor, scheduleID string, enabled bool) (Schedule, error)
- func (s *Service) TriggerSchedule(ctx context.Context, actor identity.Actor, scheduleID string) (TriggerResult, error)
- func (s *Service) WithScheduleOptions(options OptionStore, constructors map[string]ScheduleConstructor) *Service
- type TriggerResult
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job struct {
ID int64 `json:"id"`
Kind string `json:"kind"`
Queue string `json:"queue"`
State string `json:"state"`
Attempt int `json:"attempt"`
MaxAttempts int `json:"maxAttempts"`
Priority int `json:"priority"`
Args json.RawMessage `json:"args"`
Metadata json.RawMessage `json:"metadata"`
Tags []string `json:"tags"`
Errors any `json:"errors"`
AttemptedBy []string `json:"attemptedBy"`
CreatedAt time.Time `json:"createdAt"`
ScheduledAt time.Time `json:"scheduledAt"`
AttemptedAt *time.Time `json:"attemptedAt,omitempty"`
FinalizedAt *time.Time `json:"finalizedAt,omitempty"`
}
type OptionStore ¶
type OptionStore interface {
// Get 返回 name 对应 value;ok=false 表示缺失。
Get(ctx context.Context, name string) (value string, ok bool, err error)
// Set 写入 name=value。
Set(ctx context.Context, name, value string) error
}
OptionStore 读写 schedule 启用状态(通常是 web_options)。
type PostgresOptionStore ¶
type PostgresOptionStore struct {
// contains filtered or unexported fields
}
PostgresOptionStore 用 web_options 持久化 schedule 启用开关。 不走 Options 模块 catalog:这些 key 是运维内部状态,不出现在站点设置 UI。
func NewPostgresOptionStore ¶
func NewPostgresOptionStore(pool *pgxpool.Pool) *PostgresOptionStore
type Schedule ¶
type Schedule struct {
ID string `json:"id"`
JobKind string `json:"jobKind"`
Queue string `json:"queue"`
IntervalSeconds int64 `json:"intervalSeconds,omitempty"`
Cron string `json:"cron,omitempty"`
Owner string `json:"owner"`
Enabled bool `json:"enabled"`
Description string `json:"description"`
RunOnStart bool `json:"runOnStart"`
LastRunAt *time.Time `json:"lastRunAt,omitempty"`
NextRunAt *time.Time `json:"nextRunAt,omitempty"`
}
Schedule 是 admin 周期任务目录投影。 Enabled 来自 web_options 覆盖(缺失=目录默认 true)。 LastRunAt / NextRunAt 由 River 历史 + interval 估算。
type ScheduleConstructor ¶
type ScheduleConstructor func() (river.JobArgs, *river.InsertOpts)
ScheduleConstructor 构造某条 schedule 对应的 River job args(与 worker periodics 同源)。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(pool *pgxpool.Pool, client *supportjobs.Client) *Service
func (*Service) SetQueuePaused ¶
func (*Service) SetScheduleEnabled ¶
func (s *Service) SetScheduleEnabled(ctx context.Context, actor identity.Actor, scheduleID string, enabled bool) (Schedule, error)
SetScheduleEnabled 持久化启用状态;worker constructor 下次周期会读取。
func (*Service) TriggerSchedule ¶
func (s *Service) TriggerSchedule(ctx context.Context, actor identity.Actor, scheduleID string) (TriggerResult, error)
TriggerSchedule 立即入队一次对应 job(不改变周期时钟;next run 仍按 last+interval 估算)。
func (*Service) WithScheduleOptions ¶
func (s *Service) WithScheduleOptions(options OptionStore, constructors map[string]ScheduleConstructor) *Service
WithScheduleOptions 注入 option 存储与手动触发用的 constructors。
type TriggerResult ¶
type TriggerResult struct {
ScheduleID string `json:"scheduleId"`
JobID int64 `json:"jobId"`
Kind string `json:"kind"`
Queue string `json:"queue"`
// UniqueSkipped 为 true 表示 River 因唯一约束跳过插入,返回的是已有 job。
UniqueSkipped bool `json:"uniqueSkipped,omitempty"`
}
TriggerResult 是手动触发一次 schedule 的结果。
Click to show internal directories.
Click to hide internal directories.