jobs

package
v0.0.0-...-e12325a Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound         = errors.New("jobs: not found")
	ErrScheduleNotFound = errors.New("jobs: schedule not found")
	ErrScheduleDisabled = errors.New("jobs: schedule is disabled")
)

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 ListInput

type ListInput struct {
	Queue string
	Kind  string
	State string
	Limit int
}

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 Overview

type Overview struct {
	Counts map[string]int64 `json:"counts"`
	Queues []Queue          `json:"queues"`
}

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

func (*PostgresOptionStore) Get

func (s *PostgresOptionStore) Get(ctx context.Context, name string) (string, bool, error)

func (*PostgresOptionStore) Set

func (s *PostgresOptionStore) Set(ctx context.Context, name, value string) error

type Queue

type Queue struct {
	Name      string     `json:"name"`
	PausedAt  *time.Time `json:"pausedAt,omitempty"`
	UpdatedAt time.Time  `json:"updatedAt"`
	Available int64      `json:"available"`
	Running   int64      `json:"running"`
	Failed    int64      `json:"failed"`
}

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) Cancel

func (s *Service) Cancel(ctx context.Context, actor identity.Actor, id int64) (Job, error)

func (*Service) Detail

func (s *Service) Detail(ctx context.Context, actor identity.Actor, id int64) (Job, error)

func (*Service) List

func (s *Service) List(ctx context.Context, actor identity.Actor, input ListInput) ([]Job, error)

func (*Service) Overview

func (s *Service) Overview(ctx context.Context, actor identity.Actor) (Overview, error)

func (*Service) Retry

func (s *Service) Retry(ctx context.Context, actor identity.Actor, id int64) (Job, error)

func (*Service) Schedules

func (s *Service) Schedules(ctx context.Context, actor identity.Actor) ([]Schedule, error)

Schedules 返回宿主 schedule catalog,并附带运行时启用状态与 last/next run。

func (*Service) SetQueuePaused

func (s *Service) SetQueuePaused(ctx context.Context, actor identity.Actor, name string, paused bool) error

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 的结果。

Jump to

Keyboard shortcuts

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