Documentation
¶
Index ¶
- Variables
- func ApplyOnRestartStagedConfigRecords(ctx context.Context, store stagedConfigStore, serverID string) ([]*storage.StagedConfigChange, error)
- func ApplyOnRestartStagedConfigs(ctx context.Context, store stagedConfigStore, serverID string) (int, error)
- func HasPendingRestartStagedConfigRecreate(ctx context.Context, store stagedConfigStore, serverID string, ...) (bool, error)
- func ValidateModpackUpdateConfigJSON(raw string) error
- type BackupTaskConfig
- type ChunkyPregenTaskConfig
- type CommandTaskConfig
- type Config
- type ModpackUpdateTaskConfig
- type Scheduler
- func (s *Scheduler) CalculateNextRun(task *storage.ScheduledTask) (*time.Time, error)
- func (s *Scheduler) CancelExecution(executionID string) error
- func (s *Scheduler) GetStatus() SchedulerStatus
- func (s *Scheduler) HandleServerEvent(ctx context.Context, event events.Event)
- func (s *Scheduler) IsRunning() bool
- func (s *Scheduler) IsTaskRunning(taskID string) bool
- func (s *Scheduler) PrepareDeepSleepWake(ctx context.Context, server *storage.Server) error
- func (s *Scheduler) SetClientPool(pool *docker.ClientPool)
- func (s *Scheduler) SetModuleRecreator(recreate func(ctx context.Context, moduleID string) error)
- func (s *Scheduler) SetPlayerCountProvider(provider func(serverID string) int)
- func (s *Scheduler) SetSnapshotEngine(e *snapshot.Engine)
- func (s *Scheduler) Start() error
- func (s *Scheduler) StartServerForBoot(ctx context.Context, server *storage.Server) error
- func (s *Scheduler) Stop() error
- func (s *Scheduler) TriggerTask(ctx context.Context, taskID string) (*storage.TaskExecution, error)
- func (s *Scheduler) ValidateCronExpr(expr string) error
- type SchedulerStatus
- type ScriptTaskConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidModpackSource is returned for any rejected source coordinate. ErrInvalidModpackSource = errors.New("invalid modpack 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 ¶
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 ¶
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 ¶
CalculateNextRun calculates the next run time for a task based on its schedule
func (*Scheduler) CancelExecution ¶
CancelExecution cancels a running execution
func (*Scheduler) GetStatus ¶
func (s *Scheduler) GetStatus() SchedulerStatus
GetStatus returns current scheduler status
func (*Scheduler) HandleServerEvent ¶
Schedulers subscription to the central event bus
func (*Scheduler) IsTaskRunning ¶
IsTaskRunning checks if a task is currently executing
func (*Scheduler) PrepareDeepSleepWake ¶
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
SetModuleRecreator installs the module container replace used when a staged batch includes a module spec change.
func (*Scheduler) SetPlayerCountProvider ¶ added in v1.0.39
SetPlayerCountProvider installs the online-player source used for idle apply windows. It is the same function freeze and deep sleep use.
func (*Scheduler) SetSnapshotEngine ¶
SetSnapshotEngine configures custom snapshot engine
func (*Scheduler) StartServerForBoot ¶
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) TriggerTask ¶
TriggerTask manually triggers a task execution
func (*Scheduler) ValidateCronExpr ¶
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 ¶
ScriptTaskConfig represents configuration for script tasks