Documentation
¶
Index ¶
- Variables
- func GetRegisteredTaskTypes() []model.TaskType
- func ListLogStoreBackendNames() []string
- func NewTaskLogger(ctx context.Context, backendName string, taskID string) kitlog.Logger
- func RegisterFuncTaskType(taskType model.TaskType, ...)
- func RegisterLogStoreBackend(name string, factory LogStoreBackendFactory)
- func RegisterScheduledJob(def *ScheduledJobDef)
- func RegisterTaskType(taskType model.TaskType, factory TaskRunner)
- func SetDefaultLogStore(name string)
- type LogStoreBackend
- type LogStoreBackendFactory
- type PayloadBuilder
- type ProgressCallback
- type ScheduledJobDef
- type TaskRunner
Constants ¶
This section is empty.
Variables ¶
var ErrCancelled = errors.New("task cancelled")
ErrCancelled is returned by a TaskRunner when the task was cancelled via cancelCh.
Functions ¶
func GetRegisteredTaskTypes ¶
GetRegisteredTaskTypes returns all registered task type names.
func ListLogStoreBackendNames ¶
func ListLogStoreBackendNames() []string
ListLogStoreBackendNames returns the names of all registered backends. The order is not specified.
func NewTaskLogger ¶
newTaskLogger creates a logger that forwards Log() calls to the log storage service for the given task.
func RegisterFuncTaskType ¶
func RegisterFuncTaskType(taskType model.TaskType, factory func(ctx context.Context, t *model.Task, progressCallback ProgressCallback, cancelCh <-chan struct{}) (result interface{}, err error))
RegisterTaskType registers a task type and its factory. Panics if the type is already registered.
func RegisterLogStoreBackend ¶
func RegisterLogStoreBackend(name string, factory LogStoreBackendFactory)
RegisterLogStoreBackend adds a backend factory under the given name.
func RegisterScheduledJob ¶
func RegisterScheduledJob(def *ScheduledJobDef)
RegisterScheduledJob registers a scheduled job definition. Panics if ID is already registered.
func RegisterTaskType ¶
func RegisterTaskType(taskType model.TaskType, factory TaskRunner)
RegisterTaskType registers a task type and its factory. Panics if the type is already registered.
func SetDefaultLogStore ¶
func SetDefaultLogStore(name string)
SetDefaultLogStore sets the default backend name (used when Get is called with empty name).
Types ¶
type LogStoreBackend ¶
type LogStoreBackend interface {
// Write persists a log entry.
Write(ctx context.Context, refID, level, message string) error
// ListByTaskID returns log entries for the given ref ID and type, ordered by created_at asc.
ListByTaskID(ctx context.Context, refID string) ([]model.TaskLog, error)
}
LogStoreBackend is the interface for log storage. Implementations can use database, file, etc.
func GetLogStoreBackend ¶
func GetLogStoreBackend(name string) LogStoreBackend
GetLogStoreBackend returns the Backend for the given name. If name is empty, returns the default backend. Returns nil if the name is not registered.
func NewDatabaseLogStoreBackend ¶
func NewDatabaseLogStoreBackend() LogStoreBackend
NewDatabaseLogStoreBackend returns a Backend that stores logs in the database.
type LogStoreBackendFactory ¶
type LogStoreBackendFactory func() LogStoreBackend
LogStoreBackendFactory creates a Backend instance.
type PayloadBuilder ¶
type PayloadBuilder func() string
PayloadBuilder returns the JSON payload for a scheduled task run. Called each time the schedule fires.
type ProgressCallback ¶
type ProgressCallback func(progress int)
ProgressCallback is called to report task progress (0-100).
type ScheduledJobDef ¶
type ScheduledJobDef struct {
ID string
Name string
Spec string // cron expression, e.g. "0 0 * * *" for daily at midnight, If the Schedule attribute is not empty, this value is only used for the front display.
Schedule cron.Schedule
Description string
TaskType model.TaskType
PayloadBuilder PayloadBuilder
MaxRetries int
Enabled bool // if false, the job is not added to cron (or is removed)
Runner TaskRunner // if nil, the task type is not registered by the scheduler, but by the task service directly
// DisableNotAfter disables the automatic not_after deadline for tasks created
// by this job. By default (false), not_after is set to the next scheduled fire
// time so that a task missed within its scheduling window is auto-expired rather
// than running stale. Set to true for long-running or one-shot jobs that should
// not be discarded if they cannot start immediately.
DisableNotAfter bool
}
ScheduledJobDef defines a scheduled job. Registered in code; not persisted to DB.
func GetScheduledJob ¶
func GetScheduledJob(id string) *ScheduledJobDef
GetScheduledJob returns the job definition by ID, or nil.
func ListScheduledJobs ¶
func ListScheduledJobs() []*ScheduledJobDef
ListScheduledJobs returns all registered scheduled job definitions.
type TaskRunner ¶
type TaskRunner interface {
Run(ctx context.Context, t *model.Task, progressCallback ProgressCallback, cancelCh <-chan struct{}) (result interface{}, err error)
}
TaskRunner runs a single task. Run should respect cancelCh: when it is closed, the runner should stop and return. progressCallback can be called to update progress during execution.
func GetTaskRunner ¶
GetTaskRunner returns a runner for the given task type, or (nil, false) if not registered.
func NewFuncTaskRunner ¶
func NewFuncTaskRunner(factory func(ctx context.Context, t *model.Task, progressCallback ProgressCallback, cancelCh <-chan struct{}) (result interface{}, err error)) TaskRunner