Documentation
¶
Index ¶
- Constants
- func GetTask[T any](c *gin.Context)
- func GetTasks[T any](c *gin.Context)
- func NewBuilder[T any](userContext T) *builder[T]
- func NewTaskLogger[T any](storage storage.Storage) (*taskLogger[T], error)
- func PostTask[T any](c *gin.Context)
- func WithCollector(collector TaskCollectorAction, bufferSize ...int) func(*taskConfig)
- func WithConcurrency(concurrency int) func(*taskConfig)
- func WithDefaultParameters(parameters map[string]any) func(*taskConfig)
- func WithMaxRetries(maxRetries int) func(*taskConfig)
- func WithSchedule(schedule string, parameters map[string]any) func(*taskConfig)
- func WithTags(tags ...string) func(*taskConfig)
- type AnyTask
- type Collector
- type Context
- type Engine
- type Hook
- type State
- func (s *State) EncodeParameters() (string, error)
- func (s *State) GetAny(name string, defaultValue ...any) any
- func (s *State) GetBool(name string, defaultValue ...bool) bool
- func (s *State) GetFloat(name string, defaultValue ...float64) float64
- func (s *State) GetInt(name string, defaultValue ...int) int
- func (s *State) GetStr(name string, defaultValue ...string) string
- func (s *State) Serialize() ([]byte, error)
- type Task
- type TaskCollectorAction
Constants ¶
const ( StatusPending stateStatus = "pending" StatusRunning stateStatus = "running" StatusSuccess stateStatus = "success" StatusFailed stateStatus = "failed" )
Variables ¶
This section is empty.
Functions ¶
func NewBuilder ¶
func NewBuilder[T any](userContext T) *builder[T]
NewBuilder creates a new builder for the engine
func NewTaskLogger ¶ added in v1.2.12
func WithCollector ¶
func WithCollector(collector TaskCollectorAction, bufferSize ...int) func(*taskConfig)
WithCollector sets the collector for the task with optional buffer size
func WithConcurrency ¶
func WithConcurrency(concurrency int) func(*taskConfig)
WithConcurrency sets the concurrency for the task
func WithDefaultParameters ¶ added in v1.2.5
WithDefaultParameters sets the default parameters for the task
func WithMaxRetries ¶
func WithMaxRetries(maxRetries int) func(*taskConfig)
WithMaxRetries sets the max retries for the task, default is 3. -1 means infinite retries.
func WithSchedule ¶
WithSchedule adds a schedule to the task. The schedule is a cron expression with seconds precision (e.g. "0 0 * * * *").
Types ¶
type AnyTask ¶
type AnyTask interface {
Name() string
}
AnyTask is the interface that represents any task, no matter the inner type of the user context
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
func (*Collector) ConsumeWithCtx ¶
Consume consumes values from the collector
type Context ¶
Context is a temporary object into the task execution context It allow logging, outputting values and accessing the user context
func (*Context[T]) UserContext ¶
func (c *Context[T]) UserContext() T
UserContext returns the user context of the task
type Engine ¶
type Engine[T any] struct { // contains filtered or unexported fields }
Engine is the main engine for Zsched scheduler
type Hook ¶
type Hook interface {
// Initialize is called when the engine is initialized
Initialize(storage storage.Storage) error
// BeforeExecute is called before the task is executed
BeforeExecute(task AnyTask, state *State) error
// AfterExecute is called after the task is executed
AfterExecute(task AnyTask, state *State) error
}
Hook is the interface for the hooks
type State ¶
type State struct {
// id is the id of the state
ID uuid.UUID `json:"id"`
// taskID is the id of the task
TaskID uuid.UUID `json:"task_id"`
// parentID is the id of the parent task
ParentID uuid.UUID `json:"parent_id,omitempty"`
// parameters is the parameters for the task
Parameters map[string]any `json:"parameters"`
// InitializedAt is the time the state was initialized
InitializedAt time.Time `json:"initialized_at"`
// StartedAt is the time the task started executing
StartedAt time.Time `json:"started_at"`
// Iteration is the current iteration of the task
Iterations int `json:"iterations"`
Status stateStatus `json:"status"`
// LastError is the last error of the task
LastError string `json:"last_error"`
}
State is the State of the task
func (*State) EncodeParameters ¶
EncodeParameters encodes the parameters to a JSON string
type Task ¶
type Task[T any] struct { // Name of the task, should be unique without any spaces or special characters TaskName string `json:"name"` // Action to be performed by the task Action taskAction[T] `json:"-"` // contains filtered or unexported fields }
