scheduler

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidModpackSource is returned for any rejected source coordinate.
	ErrInvalidModpackSource = errors.New("invalid modpack source")
)
View Source
var ErrTaskAlreadyRunning = errors.New("task is already running")

ErrTaskAlreadyRunning is returned when a manual trigger races an in-flight execution of the same task (MINE-146, surfaced as 409).

Functions

func ApplyOnRestartStagedConfigRecords

func ApplyOnRestartStagedConfigRecords(ctx context.Context, store stagedConfigStore, serverID string) ([]*storage.StagedConfigChange, error)

ApplyOnRestartStagedConfigRecords applies all "on_restart" staged changes for a server and returns the applied records (SCH-1).

func ApplyOnRestartStagedConfigs

func ApplyOnRestartStagedConfigs(ctx context.Context, store stagedConfigStore, serverID string) (int, error)

ApplyOnRestartStagedConfigs applies all "on_restart" staged changes for a server. Call this from the server start/restart path BEFORE the container is (re)created so the fresh container picks up the merged config, e.g.:

applied, err := scheduler.ApplyOnRestartStagedConfigs(ctx, store, server.ID)

Container recreation itself stays the caller's responsibility (same split as ConfigService.UpdateServerConfig -> recreateContainer).

func HasPendingRestartStagedConfigRecreate

func HasPendingRestartStagedConfigRecreate(ctx context.Context, store stagedConfigStore, serverID string, lastStarted *time.Time) (bool, error)

HasPendingRestartStagedConfigRecreate reports whether restart-only staged changes were committed after the server's last successful start. It closes the crash/retry window between applying DB changes and recreating the Docker container.

func ValidateModpackUpdateConfigJSON

func ValidateModpackUpdateConfigJSON(raw string) error

ValidateModpackUpdateConfigJSON parses a modpack-update task config JSON and validates its git source coordinates. Exported so the task RPC service can reject a hostile config at create/update time with a clear InvalidArgument, instead of letting it sit in the database and fail (or, before this fix, execute) hours later when the schedule first fires.

Types

type BackupTaskConfig

type BackupTaskConfig struct {
	BackupName    string   `json:"backup_name"`
	Paths         []string `json:"paths"`
	Compress      bool     `json:"compress"`
	RetentionDays int      `json:"retention_days"`
	MaxBackups    int      `json:"max_backups"`
	MinBackups    int      `json:"min_backups"`
	// Exclude is extra globs on top of defaultBackupExcludes.
	Exclude []string `json:"exclude"`
	// StopForBackup stops a running or unhealthy server for the archive and
	// starts it again afterwards, including when the archive fails. A failed
	// restart is returned with the backup error so the server is not left
	// stopped silently.
	StopForBackup bool `json:"stop_for_backup"`
}

BackupTaskConfig represents configuration for backup tasks

type ChunkyPregenTaskConfig

type ChunkyPregenTaskConfig struct {
	World   string `json:"world,omitempty"`
	Radius  int    `json:"radius,omitempty"`
	Shape   string `json:"shape,omitempty"`
	CenterX int    `json:"center_x,omitempty"`
	CenterZ int    `json:"center_z,omitempty"`
}

ChunkyPregenTaskConfig represents configuration for Chunky radius pre-generation tasks

type CommandTaskConfig

type CommandTaskConfig struct {
	Command string `json:"command"`
}

CommandTaskConfig represents configuration for command tasks

type Config

type Config struct {
	CheckInterval time.Duration // How often to check for due tasks
}

Config holds scheduler configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns default scheduler configuration

type ModpackUpdateTaskConfig

type ModpackUpdateTaskConfig struct {
	GitURL                   string `json:"git_url"`
	Branch                   string `json:"branch"`
	TargetSubfolder          string `json:"target_subfolder"`
	RestartImmediately       bool   `json:"restart_immediately"`
	GracefulRestart          bool   `json:"graceful_restart"`
	GracefulCountdownSeconds int    `json:"graceful_countdown_seconds"`
	MaintenanceWindowCron    string `json:"maintenance_window_cron"`
	StageConfigUpdates       bool   `json:"stage_config_updates"`
	StageIntoBatch           bool   `json:"stage_into_batch"`
	PreUpdateSnapshot        bool   `json:"pre_update_snapshot"`      // Create volume snapshot before applying updates (MINE-23)
	AutoRollbackOnFailure    bool   `json:"auto_rollback_on_failure"` // Automatically rollback snapshot if restart/update fails
	BootGateTimeoutSecs      int    `json:"boot_gate_timeout_secs"`   // SLP boot verification after restart; 0 disables (MINE-145)
	AuthToken                string `json:"auth_token"`
}

ModpackUpdateTaskConfig matches the configuration for periodic modpack updates

type Scheduler

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

Scheduler manages scheduled tasks for all servers

func NewScheduler

func NewScheduler(store *storage.Store, docker *docker.Client, sender *command.Sender, appCfg *appconfig.Config, metricsCollector *metrics.Collector, log *logger.Logger, config ...Config) *Scheduler

NewScheduler creates a new task scheduler

func (*Scheduler) CalculateNextRun

func (s *Scheduler) CalculateNextRun(task *storage.ScheduledTask) (*time.Time, error)

CalculateNextRun calculates the next run time for a task based on its schedule

func (*Scheduler) CancelExecution

func (s *Scheduler) CancelExecution(executionID string) error

CancelExecution cancels a running execution

func (*Scheduler) GetStatus

func (s *Scheduler) GetStatus() SchedulerStatus

GetStatus returns current scheduler status

func (*Scheduler) HandleServerEvent

func (s *Scheduler) HandleServerEvent(ctx context.Context, event events.Event)

Schedulers subscription to the central event bus

func (*Scheduler) IsRunning

func (s *Scheduler) IsRunning() bool

IsRunning returns whether the scheduler is running

func (*Scheduler) IsTaskRunning

func (s *Scheduler) IsTaskRunning(taskID string) bool

IsTaskRunning checks if a task is currently executing

func (*Scheduler) PrepareDeepSleepWake

func (s *Scheduler) PrepareDeepSleepWake(ctx context.Context, server *storage.Server) error

PrepareDeepSleepWake applies restart-only staged changes and replaces the stopped container before DeepSleepManager starts it. The manager records LastStarted only after Docker reports the replacement running.

func (*Scheduler) SetClientPool

func (s *Scheduler) SetClientPool(pool *docker.ClientPool)

SetClientPool configures the multi-node Docker client pool so scheduled and deep-sleep wake tasks operate on the server's assigned node daemon.

func (*Scheduler) SetModuleRecreator added in v1.0.39

func (s *Scheduler) SetModuleRecreator(recreate func(ctx context.Context, moduleID string) error)

SetModuleRecreator installs the module container replace used when a staged batch includes a module spec change.

func (*Scheduler) SetPlayerCountProvider added in v1.0.39

func (s *Scheduler) SetPlayerCountProvider(provider func(serverID string) int)

SetPlayerCountProvider installs the online-player source used for idle apply windows. It is the same function freeze and deep sleep use.

func (*Scheduler) SetSnapshotEngine

func (s *Scheduler) SetSnapshotEngine(e *snapshot.Engine)

SetSnapshotEngine configures custom snapshot engine

func (*Scheduler) Start

func (s *Scheduler) Start() error

Start begins the scheduler loop

func (*Scheduler) StartServerForBoot

func (s *Scheduler) StartServerForBoot(ctx context.Context, server *storage.Server) error

StartServerForBoot applies pending restart-only configuration before the startup auto-start path can mark a server as successfully started. Existing running containers are left alone; only stopped containers are started.

func (*Scheduler) Stop

func (s *Scheduler) Stop() error

Stop gracefully stops the scheduler

func (*Scheduler) TriggerTask

func (s *Scheduler) TriggerTask(ctx context.Context, taskID string) (*storage.TaskExecution, error)

TriggerTask manually triggers a task execution

func (*Scheduler) ValidateCronExpr

func (s *Scheduler) ValidateCronExpr(expr string) error

ValidateCronExpr validates a cron expression

type SchedulerStatus

type SchedulerStatus struct {
	Running           bool
	ActiveTasks       int
	RunningExecutions int
	LastCheck         time.Time
	NextCheck         time.Time
}

SchedulerStatus represents the current state of the scheduler

type ScriptTaskConfig

type ScriptTaskConfig struct {
	ScriptPath string   `json:"script_path"`
	Args       []string `json:"args"`
}

ScriptTaskConfig represents configuration for script tasks

Jump to

Keyboard shortcuts

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