Documentation
¶
Index ¶
- Variables
- func ContextWithEntry(ctx context.Context, entry Entry) context.Context
- func ContextWithRunContext(ctx context.Context, run *RunContext) context.Context
- func Dispatch(ctx context.Context, entry *Entry) error
- func MustRegister(templates ...Template)
- func NextRuns(spec string, n int) ([]time.Time, error)
- func Register(templates ...Template) error
- func UseFailureHandler(handlers ...FailureHandler)
- func ValidateSpec(spec string) error
- func WithJobLogger(ctx context.Context, logger JobLogger) context.Context
- type BatchLogger
- type BuiltinLoader
- type Config
- type CreateEntryRequest
- type DatabaseLoader
- type Entry
- type EntryInfo
- type EntryRepository
- type FailureHandler
- type FailureReport
- type Job
- type JobLogger
- type JobStatus
- type Loader
- type Lock
- type LockConfig
- type Locker
- type LogConfig
- type LogEvent
- type LogFilter
- type LogLevel
- type LogStore
- type LogStreamer
- type LogWriter
- type Manager
- func (m *Manager) Config() Config
- func (m *Manager) CreateEntry(ctx context.Context, req CreateEntryRequest) (EntryInfo, error)
- func (m *Manager) DeleteEntry(ctx context.Context, id string) error
- func (m *Manager) Disable(ctx context.Context, name string) error
- func (m *Manager) DisableEntry(ctx context.Context, id string) error
- func (m *Manager) Enable(ctx context.Context, name string) error
- func (m *Manager) EnableEntry(ctx context.Context, id string) error
- func (m *Manager) GetEntry(ctx context.Context, id string) (EntryInfo, error)
- func (m *Manager) GetRuntime(ctx context.Context, id string) (RuntimeInfo, error)
- func (m *Manager) List(ctx context.Context) ([]JobStatus, error)
- func (m *Manager) ListDBTemplates(ctx context.Context) ([]TemplateInfo, error)
- func (m *Manager) ListEntries(ctx context.Context) ([]EntryInfo, error)
- func (m *Manager) ListRunLogs(ctx context.Context, filter RunLogFilter) ([]LogEvent, error)
- func (m *Manager) ListRuns(ctx context.Context, filter RunFilter) ([]RunLog, error)
- func (m *Manager) ListRuntime(ctx context.Context) ([]RuntimeInfo, error)
- func (m *Manager) ListTemplates(ctx context.Context) ([]TemplateInfo, error)
- func (m *Manager) Logs(ctx context.Context, name string, limit int) ([]RunLog, error)
- func (m *Manager) Reload(ctx context.Context) error
- func (m *Manager) RunNow(ctx context.Context, name string) error
- func (m *Manager) RunOnce(ctx context.Context, req RunOnceRequest) error
- func (m *Manager) Runner() *Runner
- func (m *Manager) Shutdown(ctx context.Context) error
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) Status(ctx context.Context) ([]JobStatus, error)
- func (m *Manager) Stop(ctx context.Context) error
- func (m *Manager) StreamLogs(ctx context.Context, filter LogFilter) (<-chan LogEvent, error)
- func (m *Manager) UpdateEntry(ctx context.Context, id string, req UpdateEntryRequest) error
- type ManagerOptions
- type MemoryLogStreamer
- type Mode
- type NoopJobLogger
- type NoopLocker
- type NoopLogWriter
- type NoopStore
- func (NoopStore) Disable(ctx context.Context, name string) error
- func (NoopStore) Enable(ctx context.Context, name string) error
- func (NoopStore) ListEnabledJobs(ctx context.Context) ([]Job, error)
- func (NoopStore) ListJobs(ctx context.Context) ([]JobStatus, error)
- func (NoopStore) Logs(ctx context.Context, name string, limit int) ([]RunLog, error)
- func (NoopStore) MarkFinished(ctx context.Context, log RunLog) error
- func (NoopStore) MarkRunning(ctx context.Context, log RunLog) error
- type Options
- type Registry
- func (r *Registry) BuiltinJobs() []Job
- func (r *Registry) Dispatch(ctx context.Context, entry *Entry) error
- func (r *Registry) Get(name string) (Template, bool)
- func (r *Registry) List() []Template
- func (r *Registry) ListDBTemplateInfo() []TemplateInfo
- func (r *Registry) ListTemplateInfo() []TemplateInfo
- func (r *Registry) MustRegister(t Template)
- func (r *Registry) Register(t Template) error
- func (r *Registry) RegisterAll(templates ...Template) error
- func (r *Registry) ValidateJob(job Job) (Template, error)
- type RunContext
- type RunFilter
- type RunHandler
- type RunLog
- type RunLogFilter
- type RunOnceRequest
- type RunResult
- type Runner
- type RunnerOptions
- type Runtime
- type RuntimeInfo
- type RuntimeMetrics
- type RuntimeState
- func (s *RuntimeState) Get(id string) (RuntimeInfo, bool)
- func (s *RuntimeState) List() []RuntimeInfo
- func (s *RuntimeState) MarkFinished(entry Entry, status RuntimeStatus, started, ended time.Time, err error)
- func (s *RuntimeState) MarkRunning(entry Entry, started time.Time)
- func (s *RuntimeState) SetSchedule(entries []Entry)
- type RuntimeStatus
- type Scheduler
- type Service
- type Source
- type Status
- type Store
- type Template
- type TemplateInfo
- type UpdateEntryRequest
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrRegistryRequired = errors.New("crontab registry is required") ErrTemplateNotFound = errors.New("crontab template not found") ErrTemplateDisabled = errors.New("crontab template disabled") ErrDynamicNotAllowed = errors.New("crontab template does not allow dynamic") ErrEntryNotFound = errors.New("crontab entry not found") ErrLocalHandlerMissing = errors.New("crontab local handler missing") ErrJobRunning = errors.New("crontab job is already running") ErrRunLimitReached = errors.New("crontab run limit reached") )
Functions ¶
func ContextWithRunContext ¶
func ContextWithRunContext(ctx context.Context, run *RunContext) context.Context
func MustRegister ¶
func MustRegister(templates ...Template)
func UseFailureHandler ¶
func UseFailureHandler(handlers ...FailureHandler)
func ValidateSpec ¶
Types ¶
type BatchLogger ¶
type BatchLogger struct {
// contains filtered or unexported fields
}
func NewBatchLogger ¶
func NewBatchLogger(writer LogWriter, batchSize int, flushInterval time.Duration) *BatchLogger
func (*BatchLogger) Start ¶
func (b *BatchLogger) Start(ctx context.Context)
func (*BatchLogger) WriteBatch ¶
func (b *BatchLogger) WriteBatch(ctx context.Context, logs []RunLog) error
type BuiltinLoader ¶
type BuiltinLoader struct {
Entries []Entry
}
type Config ¶
type Config struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled"`
Driver string `mapstructure:"driver" yaml:"driver"` // robfig | asynq
ReloadInterval time.Duration `mapstructure:"reload_interval" yaml:"reload_interval"`
InstanceID string `mapstructure:"instance_id" yaml:"instance_id"`
Lock LockConfig `mapstructure:"lock" yaml:"lock"`
Log LogConfig `mapstructure:"log" yaml:"log"`
}
func DefaultConfig ¶
func DefaultConfig() Config
type CreateEntryRequest ¶
type DatabaseLoader ¶
type DatabaseLoader struct {
Repo EntryRepository
}
type Entry ¶
type Entry struct {
ID string
Name string
TemplateKey string
Spec string
Payload string
Source Source
Enabled bool
Timeout time.Duration
Distributed bool
LockTTL time.Duration
LockKey string
MaxRunCount int64
}
func JobToEntry ¶
type EntryInfo ¶
type EntryInfo struct {
ID string `json:"id"`
Name string `json:"name"`
TemplateKey string `json:"template_key"`
Spec string `json:"spec"`
Payload string `json:"payload"`
Source Source `json:"source"`
Mode Mode `json:"mode"`
Enabled bool `json:"enabled"`
Timeout time.Duration `json:"timeout"`
Distributed bool `json:"distributed"`
LockTTL time.Duration `json:"lock_ttl"`
LockKey string `json:"lock_key"`
LastStatus Status `json:"last_status"`
LastRunAt int64 `json:"last_run_at"`
NextRunAt int64 `json:"next_run_at"`
LastError string `json:"last_error"`
RunCount int64 `json:"run_count"`
MaxRunCount int64 `json:"max_run_count"`
SuccessCount int64 `json:"success_count"`
FailCount int64 `json:"fail_count"`
SkipCount int64 `json:"skip_count"`
}
type EntryRepository ¶
type EntryRepository interface {
ListEnabled(ctx context.Context) ([]Entry, error)
ListEntries(ctx context.Context) ([]EntryInfo, error)
GetEntry(ctx context.Context, id string) (EntryInfo, error)
Create(ctx context.Context, entry Entry) (EntryInfo, error)
Update(ctx context.Context, entry Entry) error
Delete(ctx context.Context, id string) error
UpdateEnabled(ctx context.Context, id string, enabled bool) error
ListRuns(ctx context.Context, filter RunFilter) ([]RunLog, error)
}
type FailureHandler ¶
type FailureHandler func(ctx context.Context, report FailureReport)
type FailureReport ¶
type Job ¶
type Job struct {
ID string
Name string
Label string
Spec string
Source Source
Mode Mode
Enabled bool
Payload string
Queue string
TaskType string
Timeout time.Duration
Distributed bool
LockTTL time.Duration
LockKey string
MaxRunCount int64
}
func EntryToJob ¶
type JobLogger ¶
type JobLogger interface {
Info(msg string, fields ...any)
Warn(msg string, fields ...any)
Error(msg string, fields ...any)
}
func JobLoggerFromContext ¶
type LockConfig ¶
type LogStreamer ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func New ¶
func New(opts ManagerOptions) (*Manager, error)
func NewManager ¶
func NewManager(opts ManagerOptions) (*Manager, error)
func (*Manager) CreateEntry ¶
func (*Manager) GetRuntime ¶
func (*Manager) ListDBTemplates ¶
func (m *Manager) ListDBTemplates(ctx context.Context) ([]TemplateInfo, error)
func (*Manager) ListEntries ¶
func (*Manager) ListRunLogs ¶
func (*Manager) ListRuntime ¶
func (m *Manager) ListRuntime(ctx context.Context) ([]RuntimeInfo, error)
func (*Manager) ListTemplates ¶
func (m *Manager) ListTemplates(ctx context.Context) ([]TemplateInfo, error)
func (*Manager) StreamLogs ¶
func (*Manager) UpdateEntry ¶
type ManagerOptions ¶
type ManagerOptions struct {
Config Config
Registry *Registry
Store Store
Scheduler Scheduler
Locker Locker
Logger LogWriter
Repository EntryRepository
Runner *Runner
Runtime *RuntimeState
LogStore LogStore
Streamer LogStreamer
RuntimeLogger *zap.Logger
}
type MemoryLogStreamer ¶
type MemoryLogStreamer struct {
// contains filtered or unexported fields
}
func NewMemoryLogStreamer ¶
func NewMemoryLogStreamer() *MemoryLogStreamer
type NoopJobLogger ¶
type NoopJobLogger struct{}
func (NoopJobLogger) Error ¶
func (NoopJobLogger) Error(msg string, fields ...any)
func (NoopJobLogger) Info ¶
func (NoopJobLogger) Info(msg string, fields ...any)
func (NoopJobLogger) Warn ¶
func (NoopJobLogger) Warn(msg string, fields ...any)
type NoopLogWriter ¶
type NoopLogWriter struct{}
func (NoopLogWriter) WriteBatch ¶
func (NoopLogWriter) WriteBatch(ctx context.Context, logs []RunLog) error
type NoopStore ¶
type NoopStore struct{}
func (NoopStore) ListEnabledJobs ¶
func (NoopStore) MarkFinished ¶
type Options ¶
type Options struct {
WithSeconds bool
AutoLoadDB bool
Distributed bool
Locker Locker
ShutdownTimeout time.Duration
StrictLoad bool
}
func DefaultOptions ¶
func DefaultOptions() Options
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) BuiltinJobs ¶
func (*Registry) ListDBTemplateInfo ¶
func (r *Registry) ListDBTemplateInfo() []TemplateInfo
func (*Registry) ListTemplateInfo ¶
func (r *Registry) ListTemplateInfo() []TemplateInfo
func (*Registry) MustRegister ¶
func (*Registry) RegisterAll ¶
type RunContext ¶
type RunContext struct {
Job Job
Template Template
Entry Entry
RunID string
StartedAt time.Time
InstanceID string
Result RunResult
// contains filtered or unexported fields
}
func RunContextFromContext ¶
func RunContextFromContext(ctx context.Context) (*RunContext, bool)
func (*RunContext) Context ¶
func (c *RunContext) Context() context.Context
func (*RunContext) SetContext ¶
func (c *RunContext) SetContext(ctx context.Context)
type RunHandler ¶
type RunHandler func(*RunContext) RunResult
func RunHandlerFromFunc ¶
func RunHandlerFromFunc(handler func(context.Context, Job) error) RunHandler
type RunLogFilter ¶
type RunOnceRequest ¶
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
func NewRunner ¶
func NewRunner(opts RunnerOptions) *Runner
func (*Runner) LastRunStatus ¶
type RunnerOptions ¶
type RunnerOptions struct {
Config Config
Registry *Registry
Store Store
Locker Locker
Logger LogWriter
LogStore LogStore
Streamer LogStreamer
RuntimeLogger *zap.Logger
Runtime *RuntimeState
}
type RuntimeInfo ¶
type RuntimeInfo struct {
EntryID string `json:"entry_id"`
TemplateKey string `json:"template_key"`
Status RuntimeStatus `json:"status"`
PrevTime time.Time `json:"prev_time"`
NextTime time.Time `json:"next_time"`
LastStartAt time.Time `json:"last_start_at"`
LastEndAt time.Time `json:"last_end_at"`
LastDuration time.Duration `json:"last_duration"`
LastError string `json:"last_error"`
RunCount int64 `json:"run_count"`
SuccessCount int64 `json:"success_count"`
FailCount int64 `json:"fail_count"`
SkipCount int64 `json:"skip_count"`
}
type RuntimeMetrics ¶
type RuntimeMetrics struct {
CrontabExecuteTotal int64 `json:"crontab_execute_total"`
CrontabExecuteSuccessTotal int64 `json:"crontab_execute_success_total"`
CrontabExecuteFailedTotal int64 `json:"crontab_execute_failed_total"`
CrontabExecuteDuration time.Duration `json:"crontab_execute_duration"`
CrontabOverlapSkippedTotal int64 `json:"crontab_overlap_skipped_total"`
CrontabTimeoutTotal int64 `json:"crontab_timeout_total"`
}
func RuntimeMetricsSnapshot ¶
func RuntimeMetricsSnapshot() RuntimeMetrics
type RuntimeState ¶
type RuntimeState struct {
// contains filtered or unexported fields
}
func NewRuntimeState ¶
func NewRuntimeState() *RuntimeState
func (*RuntimeState) Get ¶
func (s *RuntimeState) Get(id string) (RuntimeInfo, bool)
func (*RuntimeState) List ¶
func (s *RuntimeState) List() []RuntimeInfo
func (*RuntimeState) MarkFinished ¶
func (s *RuntimeState) MarkFinished(entry Entry, status RuntimeStatus, started, ended time.Time, err error)
func (*RuntimeState) MarkRunning ¶
func (s *RuntimeState) MarkRunning(entry Entry, started time.Time)
func (*RuntimeState) SetSchedule ¶
func (s *RuntimeState) SetSchedule(entries []Entry)
type RuntimeStatus ¶
type RuntimeStatus string
const ( RuntimeWaiting RuntimeStatus = "waiting" RuntimeRunning RuntimeStatus = "running" RuntimeSuccess RuntimeStatus = "success" RuntimeFailed RuntimeStatus = "failed" RuntimeSkipped RuntimeStatus = "skipped" RuntimeDisabled RuntimeStatus = "disabled" )
type Service ¶
type Service interface {
Start(ctx context.Context) error
Shutdown(ctx context.Context) error
Reload(ctx context.Context) error
ListTemplates(ctx context.Context) ([]TemplateInfo, error)
ListDBTemplates(ctx context.Context) ([]TemplateInfo, error)
ListEntries(ctx context.Context) ([]EntryInfo, error)
GetEntry(ctx context.Context, id string) (EntryInfo, error)
CreateEntry(ctx context.Context, req CreateEntryRequest) (EntryInfo, error)
UpdateEntry(ctx context.Context, id string, req UpdateEntryRequest) error
DeleteEntry(ctx context.Context, id string) error
EnableEntry(ctx context.Context, id string) error
DisableEntry(ctx context.Context, id string) error
RunOnce(ctx context.Context, req RunOnceRequest) error
ListRuntime(ctx context.Context) ([]RuntimeInfo, error)
GetRuntime(ctx context.Context, id string) (RuntimeInfo, error)
ListRuns(ctx context.Context, filter RunFilter) ([]RunLog, error)
ListRunLogs(ctx context.Context, filter RunLogFilter) ([]LogEvent, error)
StreamLogs(ctx context.Context, filter LogFilter) (<-chan LogEvent, error)
}
type Status ¶
type Status string
const ( StatusPending Status = "pending" StatusRunning Status = "running" StatusSuccess Status = "success" StatusFailed Status = "failed" StatusSkipped Status = "skipped" StatusTimeout Status = "timeout" StatusPanic Status = "panic" StatusLocked Status = "locked" StatusDisabled Status = "disabled" StatusTemplateMissing Status = "template_missing" StatusTemplateDisabled Status = "template_disabled" )
type Store ¶
type Store interface {
ListEnabledJobs(ctx context.Context) ([]Job, error)
ListJobs(ctx context.Context) ([]JobStatus, error)
MarkRunning(ctx context.Context, log RunLog) error
MarkFinished(ctx context.Context, log RunLog) error
Enable(ctx context.Context, name string) error
Disable(ctx context.Context, name string) error
Logs(ctx context.Context, name string, limit int) ([]RunLog, error)
}
type TemplateInfo ¶
type TemplateInfo struct {
Key string `json:"key"`
Name string `json:"name"`
Label string `json:"label"`
Desc string `json:"desc"`
Description string `json:"description"`
Spec string `json:"spec"`
Mode string `json:"mode"`
Enabled bool `json:"enabled"`
AllowBuiltin bool `json:"allow_builtin"`
AllowDB bool `json:"allow_db"`
AllowOverlap bool `json:"allow_overlap"`
LogDisabled bool `json:"log_disabled"`
DefaultSpec string `json:"default_spec"`
DefaultPayload string `json:"default_payload"`
DefaultQueue string `json:"default_queue"`
DefaultTaskType string `json:"default_task_type"`
PayloadFormat string `json:"payload_format"`
PayloadSchema string `json:"payload_schema"`
Timeout time.Duration `json:"timeout"`
TimeoutSec int `json:"timeout_sec"`
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.