schedule

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServiceNotFound   = errors.New("service not found")
	ErrServiceNotRunning = errors.New("service is not running")
)

Generic errors

View Source
var ErrJobCanBeRemovedOnly = errors.New("job can be removed only")

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) 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

type Config

type Config struct {
	ProfileName             string
	CommandName             string // restic command
	Schedules               []string
	Permission              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
	IgnoreOnBattery         bool
	IgnoreOnBatteryLessThan int
	AfterNetworkOnline      bool
	SystemdDropInFiles      []string
	// 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)
	DisplayParsedSchedules(command string, events []*calendar.Event)
	DisplaySchedules(command string, schedules []string) error
	DisplayStatus(profileName string) error
	CreateJob(job *Config, schedules []*calendar.Event, permission string) error
	RemoveJob(job *Config, permission string) error
	DisplayJobStatus(job *Config) error
}

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) 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 string) error

CreateJob is creating the crontab

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) DisplayParsedSchedules added in v0.16.1

func (h *HandlerCrond) DisplayParsedSchedules(command string, events []*calendar.Event)

func (*HandlerCrond) DisplaySchedules added in v0.16.1

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

DisplaySchedules does nothing with crond

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 string) 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) Close added in v0.16.1

func (h *HandlerSystemd) Close()

Close does nothing with systemd

func (*HandlerSystemd) CreateJob added in v0.16.1

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

CreateJob is creating the systemd unit and activating it

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) DisplayParsedSchedules added in v0.16.1

func (h *HandlerSystemd) DisplayParsedSchedules(command string, events []*calendar.Event)

DisplayParsedSchedules does nothing with systemd

func (*HandlerSystemd) DisplaySchedules added in v0.16.1

func (h *HandlerSystemd) DisplaySchedules(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

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 string) error

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

type Job

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

Job scheduler

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 string

Permission is either system or user

const (
	PermissionUser   Permission = "user"
	PermissionSystem Permission = "system"
)

Permission

func (Permission) String

func (p Permission) String() string

String returns either "user" or "system"

type Scheduler added in v0.11.0

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

Scheduler

func NewScheduler added in v0.11.0

func NewScheduler(handler Handler, profileName string) *Scheduler

NewScheduler creates a Scheduler object

func (*Scheduler) Close added in v0.11.0

func (s *Scheduler) Close()

Close

func (*Scheduler) DisplayStatus added in v0.11.0

func (s *Scheduler) DisplayStatus()

DisplayStatus

func (*Scheduler) Init added in v0.11.0

func (s *Scheduler) Init() error

Init

func (*Scheduler) NewJob added in v0.11.0

func (s *Scheduler) NewJob(config *Config) *Job

NewJob instantiates a Job object (of SchedulerJob interface) to schedule jobs

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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