Help us shape the future of Go! Take the 2026 Go Developer Survey

scheduler

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackupTaskConfig

type BackupTaskConfig struct {
	RetentionCount int    `json:"retention_count"`
	StoragePath    string `json:"storage_path,omitempty"`
}

type CommandTaskConfig

type CommandTaskConfig struct {
	Service string `json:"service"`
	Command string `json:"command"`
	Timeout int    `json:"timeout"`
}

type CreateTaskRequest

type CreateTaskRequest struct {
	Name           string     `json:"name" binding:"required"`
	Type           TaskType   `json:"type" binding:"required"`
	DeploymentName string     `json:"deployment_name" binding:"required"`
	CronExpr       string     `json:"cron_expr" binding:"required"`
	Enabled        bool       `json:"enabled"`
	Config         TaskConfig `json:"config"`
}

type DB

type DB struct {
	// contains filtered or unexported fields
}

func NewDB

func NewDB(deploymentsPath string) (*DB, error)

func (*DB) CleanupOldExecutions

func (db *DB) CleanupOldExecutions(olderThan time.Duration) (int64, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) CreateExecution

func (db *DB) CreateExecution(exec *TaskExecution) (int64, error)

func (*DB) CreateTask

func (db *DB) CreateTask(task *ScheduledTask) (int64, error)

func (*DB) DeleteTask

func (db *DB) DeleteTask(id int64) error

func (*DB) GetAllTasks

func (db *DB) GetAllTasks() ([]ScheduledTask, error)

func (*DB) GetDueTasks

func (db *DB) GetDueTasks() ([]ScheduledTask, error)

func (*DB) GetEnabledTasks

func (db *DB) GetEnabledTasks() ([]ScheduledTask, error)

func (*DB) GetExecutionsByTask

func (db *DB) GetExecutionsByTask(taskID int64, limit int) ([]TaskExecution, error)

func (*DB) GetRecentExecutions

func (db *DB) GetRecentExecutions(limit int) ([]TaskExecution, error)

func (*DB) GetTask

func (db *DB) GetTask(id int64) (*ScheduledTask, error)

func (*DB) GetTasksByDeployment

func (db *DB) GetTasksByDeployment(deploymentName string) ([]ScheduledTask, error)

func (*DB) UpdateExecution

func (db *DB) UpdateExecution(id int64, status TaskStatus, output, errMsg string, endedAt time.Time, durationMs int64) error

func (*DB) UpdateTask

func (db *DB) UpdateTask(id int64, req *UpdateTaskRequest) error

func (*DB) UpdateTaskNextRun

func (db *DB) UpdateTaskNextRun(id int64, nextRun time.Time) error

func (*DB) UpdateTaskRun

func (db *DB) UpdateTaskRun(id int64, lastRun, nextRun time.Time) error

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

func NewExecutor

func NewExecutor(backupManager *backup.Manager, dockerManager *docker.Manager) *Executor

func (*Executor) ExecuteBackup

func (e *Executor) ExecuteBackup(ctx context.Context, deploymentName string, config *BackupTaskConfig) (string, error)

func (*Executor) ExecuteCommand

func (e *Executor) ExecuteCommand(ctx context.Context, deploymentName string, config *CommandTaskConfig) (string, error)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(deploymentsPath string, executor TaskExecutor) (*Manager, error)

func (*Manager) Cleanup

func (m *Manager) Cleanup(olderThan time.Duration) (int64, error)

func (*Manager) CreateTask

func (m *Manager) CreateTask(req *CreateTaskRequest) (*ScheduledTask, error)

func (*Manager) DeleteTask

func (m *Manager) DeleteTask(id int64) error

func (*Manager) GetAllTasks

func (m *Manager) GetAllTasks() ([]ScheduledTask, error)

func (*Manager) GetRecentExecutions

func (m *Manager) GetRecentExecutions(limit int) ([]TaskExecution, error)

func (*Manager) GetTask

func (m *Manager) GetTask(id int64) (*ScheduledTask, error)

func (*Manager) GetTaskExecutions

func (m *Manager) GetTaskExecutions(taskID int64, limit int) ([]TaskExecution, error)

func (*Manager) GetTasksByDeployment

func (m *Manager) GetTasksByDeployment(deploymentName string) ([]ScheduledTask, error)

func (*Manager) RunTaskNow

func (m *Manager) RunTaskNow(id int64) error

func (*Manager) Start

func (m *Manager) Start()

func (*Manager) Stop

func (m *Manager) Stop()

func (*Manager) UpdateTask

func (m *Manager) UpdateTask(id int64, req *UpdateTaskRequest) (*ScheduledTask, error)

func (*Manager) ValidateCronExpr

func (m *Manager) ValidateCronExpr(cronExpr string) error

type ScheduledTask

type ScheduledTask struct {
	ID             int64      `json:"id"`
	Name           string     `json:"name"`
	Type           TaskType   `json:"type"`
	DeploymentName string     `json:"deployment_name"`
	CronExpr       string     `json:"cron_expr"`
	Enabled        bool       `json:"enabled"`
	Config         TaskConfig `json:"config"`
	LastRun        *time.Time `json:"last_run,omitempty"`
	NextRun        *time.Time `json:"next_run,omitempty"`
	CreatedAt      time.Time  `json:"created_at"`
	UpdatedAt      time.Time  `json:"updated_at"`
}

type TaskConfig

type TaskConfig struct {
	// For backup tasks
	BackupConfig *BackupTaskConfig `json:"backup_config,omitempty"`
	// For command tasks
	CommandConfig *CommandTaskConfig `json:"command_config,omitempty"`
}

type TaskExecution

type TaskExecution struct {
	ID        int64      `json:"id"`
	TaskID    int64      `json:"task_id"`
	Status    TaskStatus `json:"status"`
	Output    string     `json:"output,omitempty"`
	Error     string     `json:"error,omitempty"`
	StartedAt time.Time  `json:"started_at"`
	EndedAt   *time.Time `json:"ended_at,omitempty"`
	Duration  int64      `json:"duration_ms,omitempty"`
}

type TaskExecutor

type TaskExecutor interface {
	ExecuteBackup(ctx context.Context, deploymentName string, config *BackupTaskConfig) (string, error)
	ExecuteCommand(ctx context.Context, deploymentName string, config *CommandTaskConfig) (string, error)
}

type TaskStatus

type TaskStatus string
const (
	TaskStatusPending   TaskStatus = "pending"
	TaskStatusRunning   TaskStatus = "running"
	TaskStatusCompleted TaskStatus = "completed"
	TaskStatusFailed    TaskStatus = "failed"
)

type TaskType

type TaskType string
const (
	TaskTypeBackup  TaskType = "backup"
	TaskTypeCommand TaskType = "command"
)

type UpdateTaskRequest

type UpdateTaskRequest struct {
	Name     *string     `json:"name,omitempty"`
	CronExpr *string     `json:"cron_expr,omitempty"`
	Enabled  *bool       `json:"enabled,omitempty"`
	Config   *TaskConfig `json:"config,omitempty"`
}

Jump to

Keyboard shortcuts

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