schedule

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrScheduledJobNotFound   = errors.New("scheduled job not found")
	ErrScheduledJobNotRunning = errors.New("scheduled job is not running")
)

Generic errors

View Source
var ErrJobCanBeRemovedOnly = errors.New("this job is marked for removal only and cannot be created or modified")

Functions

func AddHandlerProvider added in v0.27.0

func AddHandlerProvider(provider HandlerProvider)

AddHandlerProvider allows to register a provider for a SchedulerConfig handler

Types

type CommandArguments added in v0.29.0

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

func NewCommandArguments added in v0.29.0

func NewCommandArguments(args []string) CommandArguments

func (CommandArguments) ConfigFile added in v0.30.0

func (ca CommandArguments) ConfigFile() string

ConfigFile returns the value of the --config argument, if present. if multiple --config are present, it will return the last value

func (CommandArguments) RawArgs added in v0.29.0

func (ca CommandArguments) RawArgs() []string

func (CommandArguments) String added in v0.29.0

func (ca CommandArguments) String() string

String returns the arguments as a string, with quotes around arguments that contain spaces

func (CommandArguments) Trim added in v0.30.0

func (ca CommandArguments) Trim(removeArgs []string) CommandArguments

Trim returns a new CommandArguments with the specified flags removed from the arguments

type Config

type Config struct {
	ProfileName        string
	CommandName        string // restic command
	Schedules          []string
	Permission         string
	RunLevel           string
	WorkingDirectory   string
	Command            string // path to resticprofile executable
	Arguments          CommandArguments
	Environment        []string
	JobDescription     string
	TimerDescription   string
	Priority           string // Priority is either "background" or "standard"
	ConfigFile         string
	Flags              map[string]string // flags added to the command line
	AfterNetworkOnline bool
	SystemdDropInFiles []string
	HideWindow         bool
	// contains filtered or unexported fields
}

Config contains all information to schedule a profile command

func NewRemoveOnlyConfig added in v0.12.0

func NewRemoveOnlyConfig(profileName, commandName string) *Config

NewRemoveOnlyConfig creates a job config that may be used to call Job.Remove() on a scheduled job

func (*Config) GetFlag added in v0.11.0

func (s *Config) GetFlag(name string) (string, bool)

func (*Config) GetPriority added in v0.27.0

func (s *Config) GetPriority() string

Priority is either "background" or "standard"

func (*Config) SetCommand added in v0.27.0

func (s *Config) SetCommand(wd, command string, args []string)

SetCommand sets the command details for scheduling. Arguments are automatically processed to ensure proper handling of paths with spaces and special characters.

func (*Config) SetFlag added in v0.27.0

func (s *Config) SetFlag(name, value string)

type Handler added in v0.16.1

type Handler interface {
	Init() error
	Close()
	ParseSchedules(schedules []string) ([]*calendar.Event, error)
	DisplaySchedules(profile, command string, schedules []string) error
	DisplayStatus(profileName string) error
	CreateJob(job *Config, schedules []*calendar.Event, permission Permission) error
	RemoveJob(job *Config, permission Permission) error
	DisplayJobStatus(job *Config) error
	// Scheduled can return configs at the same time as an error: it means some configs are fine but some others cannot be loaded properly
	Scheduled(profileName string) ([]Config, error)
	// DetectSchedulePermission returns the permission defined from the configuration,
	// or the best guess considering the current user permission.
	// safe specifies whether a guess may lead to a too broad or too narrow file access permission.
	DetectSchedulePermission(permission Permission) (Permission, bool)
	// CheckPermission returns true if the user is allowed to access the job.
	CheckPermission(user user.User, p Permission) bool
}

Handler interface for the scheduling software available on the system

func FindHandler added in v0.27.0

func FindHandler(config SchedulerConfig) Handler

FindHandler creates a schedule handler depending on the configuration or nil if the config is not supported

func NewHandler added in v0.16.1

func NewHandler(config SchedulerConfig) Handler

NewHandler creates a schedule handler depending on the configuration, panics if the config is not supported

type HandlerCrond added in v0.16.1

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

HandlerCrond is a handler for crond scheduling

func NewHandlerCrond added in v0.16.1

func NewHandlerCrond(config SchedulerConfig) *HandlerCrond

NewHandlerCrond creates a new handler for crond scheduling

func (*HandlerCrond) CheckPermission added in v0.30.0

func (h *HandlerCrond) CheckPermission(user user.User, p Permission) bool

CheckPermission returns true if the user is allowed to access the job.

func (*HandlerCrond) Close added in v0.16.1

func (h *HandlerCrond) Close()

Close does nothing with crond

func (*HandlerCrond) CreateJob added in v0.16.1

func (h *HandlerCrond) CreateJob(job *Config, schedules []*calendar.Event, permission Permission) error

CreateJob is creating the crontab

func (*HandlerCrond) DetectSchedulePermission added in v0.30.0

func (h *HandlerCrond) DetectSchedulePermission(p Permission) (Permission, bool)

DetectSchedulePermission returns the permission defined from the configuration, or the best guess considering the current user permission. safe specifies whether a guess may lead to a too broad or too narrow file access permission.

func (*HandlerCrond) DisplayJobStatus added in v0.16.1

func (h *HandlerCrond) DisplayJobStatus(job *Config) error

DisplayJobStatus has nothing to display (crond doesn't provide running information)

func (*HandlerCrond) DisplaySchedules added in v0.16.1

func (h *HandlerCrond) DisplaySchedules(profile, command string, schedules []string) error

func (*HandlerCrond) DisplayStatus added in v0.16.1

func (h *HandlerCrond) DisplayStatus(profileName string) error

DisplayStatus does nothing with crond

func (*HandlerCrond) Init added in v0.16.1

func (h *HandlerCrond) Init() error

Init verifies crond is available on this system

func (*HandlerCrond) ParseSchedules added in v0.16.1

func (h *HandlerCrond) ParseSchedules(schedules []string) ([]*calendar.Event, error)

func (*HandlerCrond) RemoveJob added in v0.16.1

func (h *HandlerCrond) RemoveJob(job *Config, permission Permission) error

func (*HandlerCrond) Scheduled added in v0.30.0

func (h *HandlerCrond) Scheduled(profileName string) ([]Config, error)

type HandlerProvider added in v0.27.0

type HandlerProvider func(config SchedulerConfig, fallback bool) Handler

type HandlerSystemd added in v0.16.1

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

HandlerSystemd is a handler to schedule tasks using systemd

func NewHandlerSystemd added in v0.16.1

func NewHandlerSystemd(config SchedulerConfig) *HandlerSystemd

NewHandlerSystemd creates a new handler to schedule jobs using systemd

func (*HandlerSystemd) CheckPermission added in v0.30.0

func (h *HandlerSystemd) CheckPermission(user user.User, p Permission) bool

CheckPermission returns true if the user is allowed to access the job.

func (*HandlerSystemd) Close added in v0.16.1

func (h *HandlerSystemd) Close()

Close runs systemctl daemon-reload if needed

func (*HandlerSystemd) CreateJob added in v0.16.1

func (h *HandlerSystemd) CreateJob(job *Config, schedules []*calendar.Event, permission Permission) error

CreateJob is creating the systemd unit and activating it

func (*HandlerSystemd) DetectSchedulePermission added in v0.30.0

func (h *HandlerSystemd) DetectSchedulePermission(p Permission) (Permission, bool)

detectSchedulePermission returns the permission defined from the configuration, or the best guess considering the current user permission. safe specifies whether a guess may lead to a too broad or too narrow file access permission.

func (*HandlerSystemd) DisplayJobStatus added in v0.16.1

func (h *HandlerSystemd) DisplayJobStatus(job *Config) error

DisplayJobStatus displays information of a systemd service/timer

func (*HandlerSystemd) DisplaySchedules added in v0.16.1

func (h *HandlerSystemd) DisplaySchedules(profile, command string, schedules []string) error

DisplaySchedules displays the schedules through the systemd-analyze command

func (*HandlerSystemd) DisplayStatus added in v0.16.1

func (h *HandlerSystemd) DisplayStatus(profileName string) error

Timers summary =============== NEXT LEFT LAST PASSED UNIT ACTIVATES Tue 2024-10-29 18:45:00 GMT 28min left Tue 2024-10-29 18:16:09 GMT 38s ago resticprofile-copy@profile-self.timer resticprofile-copy@profile-self.service

1 timers listed.

func (*HandlerSystemd) Init added in v0.16.1

func (h *HandlerSystemd) Init() error

Init verifies systemd is available on this system

func (*HandlerSystemd) ParseSchedules added in v0.16.1

func (h *HandlerSystemd) ParseSchedules(schedules []string) ([]*calendar.Event, error)

ParseSchedules always returns nil on systemd

func (*HandlerSystemd) RemoveJob added in v0.16.1

func (h *HandlerSystemd) RemoveJob(job *Config, permission Permission) error

RemoveJob is disabling the systemd unit and deleting the timer and service files

func (*HandlerSystemd) Scheduled added in v0.30.0

func (h *HandlerSystemd) Scheduled(profileName string) ([]Config, error)

type Job

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

Job scheduler

func NewJob

func NewJob(handler Handler, config *Config) *Job

func (*Job) Accessible added in v0.12.0

func (j *Job) Accessible() bool

Accessible checks if the current user is permitted to access the job

func (*Job) Create

func (j *Job) Create() error

Create a new job

func (*Job) Remove

func (j *Job) Remove() error

Remove a job

func (*Job) RemoveOnly added in v0.12.0

func (j *Job) RemoveOnly() bool

RemoveOnly returns true if this job can be removed only

func (*Job) Status

func (j *Job) Status() error

Status of a job

type Permission

type Permission int
const (
	PermissionAuto Permission = iota
	PermissionSystem
	PermissionUserBackground
	PermissionUserLoggedOn
)

func PermissionFromConfig added in v0.30.0

func PermissionFromConfig(permission string) Permission

func (Permission) String

func (p Permission) String() string

type SchedulerConfig added in v0.16.1

type SchedulerConfig interface {
	// Type of scheduler config ("windows", "launchd", "crond", "systemd" or "" for OS default)
	Type() string
	Convert(typeName string) SchedulerConfig
}

func NewSchedulerConfig added in v0.16.1

func NewSchedulerConfig(global *config.Global) SchedulerConfig

type SchedulerCrond added in v0.16.1

type SchedulerCrond struct {
	CrontabFile   string
	CrontabBinary string
	Username      string
}

SchedulerCrond configures crond compatible schedulers, either needs CrontabBinary or CrontabFile

func (SchedulerCrond) Convert added in v0.27.0

func (s SchedulerCrond) Convert(_ string) SchedulerConfig

func (SchedulerCrond) Type added in v0.16.1

func (s SchedulerCrond) Type() string

type SchedulerDefaultOS added in v0.16.1

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

func (SchedulerDefaultOS) Convert added in v0.27.0

func (s SchedulerDefaultOS) Convert(typeName string) SchedulerConfig

func (SchedulerDefaultOS) Type added in v0.16.1

func (s SchedulerDefaultOS) Type() string

type SchedulerLaunchd added in v0.16.1

type SchedulerLaunchd struct{}

func (SchedulerLaunchd) Convert added in v0.27.0

func (SchedulerLaunchd) Type added in v0.16.1

func (s SchedulerLaunchd) Type() string

type SchedulerSystemd added in v0.16.1

type SchedulerSystemd struct {
	UnitTemplate  string
	TimerTemplate string
	Nice          int
	IONiceClass   int
	IONiceLevel   int
}

func (SchedulerSystemd) Convert added in v0.27.0

func (SchedulerSystemd) Type added in v0.16.1

func (s SchedulerSystemd) Type() string

type SchedulerWindows added in v0.16.1

type SchedulerWindows struct{}

func (SchedulerWindows) Convert added in v0.27.0

func (SchedulerWindows) Type added in v0.16.1

func (s SchedulerWindows) Type() string

type SystemdUnit added in v0.30.0

type SystemdUnit struct {
	Unit        string `json:"unit"`
	Load        string `json:"load"`
	Active      string `json:"active"`
	Sub         string `json:"sub"`
	Description string `json:"description"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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