task

package
v0.0.0-...-38575d5 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: AGPL-3.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const (
	StatusRunning     = "running"
	StatusComplete    = "complete"
	StatusError       = "error"
	StatusReady       = "ready"
	StatusInit        = "init"
	StatusPendingStop = "pending_stop"
	StatusStopped     = "stopped"
)
View Source
const (
	Pending  State = "PENDING"
	Running  State = "STARTED"
	Canceled       = "CANCELED"
	Finished       = "FINISHED"
)
View Source
const Crontab = "crontab"
View Source
const Interval = "interval"
View Source
const Transient = "transient"

Variables

View Source
var Tasks = sync.Map{}

Functions

func DeleteTask

func DeleteTask(id string)

func IsEnded

func IsEnded(status string) bool

func MustGetString

func MustGetString(ctx context.Context, key string) string

func RegisterScheduleTask

func RegisterScheduleTask(task ScheduleTask) (taskID string)

func RunTasks

func RunTasks()

func RunWithContext

func RunWithContext(tag string, f func(ctx context.Context) error, ctxInput context.Context) (taskID string)

func RunWithinGroup

func RunWithinGroup(groupName string, f func(ctx context.Context) error) (taskID string)

func StartTask

func StartTask(id string)

func StopAllTasks

func StopAllTasks()

func StopTask

func StopTask(id string)

func StopTasks

func StopTasks()

Types

type Metadata

type Metadata struct {
	Type   string                 `json:"type" elastic_mapping:"type: { type: keyword }"`
	Labels map[string]interface{} `json:"labels" elastic_mapping:"labels: { type: object }"`
}

type ScheduleTask

type ScheduleTask struct {
	ID          string     `config:"id" json:"id,omitempty"`
	Group       string     `config:"group" json:"group,omitempty"`
	Description string     `config:"description" json:"description,omitempty"`
	Type        string     `config:"type" json:"type,omitempty"`
	Interval    string     `config:"interval" json:"interval,omitempty"`
	Crontab     string     `config:"crontab" json:"crontab,omitempty"`
	CreateTime  time.Time  `config:"create_time" json:"create_time,omitempty"`
	StartTime   *time.Time `config:"start_time" json:"start_time,omitempty"`
	EndTime     *time.Time `config:"end_time" json:"end_time,omitempty"`

	// Ensures the task runs as a singleton, preventing duplicate executions when previous attempt is not finished.
	Singleton bool `config:"singleton" json:"singleton,omitempty"`

	Task func(ctx context.Context) `config:"-" json:"-"`

	State State           `config:"state" json:"state,omitempty"`
	Ctx   context.Context `config:"-" json:"-"` //for transient task
	// contains filtered or unexported fields
}

type State

type State string

type Task

type Task struct {
	orm.ORMObjectBase

	ParentId          []string   `json:"parent_id,omitempty" elastic_mapping:"parent_id: { type: keyword }"`
	StartTimeInMillis int64      `json:"start_time_in_millis" elastic_mapping:"start_time_in_millis: { type: long }"`
	Cancellable       bool       `json:"cancellable" elastic_mapping:"cancellable: { type: boolean }"`
	Runnable          bool       `json:"runnable" elastic_mapping:"runnable: { type: boolean }"`
	Metadata          Metadata   `json:"metadata" elastic_mapping:"metadata: { type: object }"`
	Status            string     `json:"status"  elastic_mapping:"status: { type: keyword }"`
	Description       string     `json:"description,omitempty" elastic_mapping:"description: { type: text }"`
	ConfigString      string     `json:"config_string" elastic_mapping:"config_string:{ type: text }"`
	CompletedTime     *time.Time `json:"completed_time,omitempty" elastic_mapping:"completed_time: { type: date }"`
	RetryTimes        int        `json:"retry_times,omitempty" elastic_mapping:"retry_times: { type: integer }"`
	// DEPRECATED: used by old tasks
	Config_ interface{} `json:"config,omitempty" elastic_mapping:"config:{type: object,enabled:false }"`
}

type TaskResult

type TaskResult struct {
	Success bool   `json:"success" elastic_mapping:"success: { type: boolean }"`
	Error   string `json:"error,omitempty" elastic_mapping:"error: { type: text }"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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