scheduler

package
v0.0.0-...-2bffabc Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Value string

	// If not an empty string, this is what will be logged to the logger when
	// sending the command. The format will be "%v: %v", log, content.
	Log string

	// The interval at which the command should be rescheduled. Set to 0 to
	// disable.
	Interval time.Duration

	// If AwaitResume is true, the scheduler will wait for a resume call before
	// executing the next command.
	AwaitResume bool

	RescheduleAsPriority bool

	// Next is a pointer to the command that will be rescheduled if interval is
	// not 0. If this is nil this command itself will be rescheduled. Using this
	// feature might be useful when you want to create a chain of commands that
	// work together but have, for example, different values for Command.Value.
	Next *Command

	// The amount of times to reschedule the command in total. Set to 0 to
	// reschedule indefinitely. To run a command once, the interval should be
	// set to 0, not the amount.
	Amount uint

	// If this function returns false, the command will not be sent but will be
	// rescheduled. It does not count as an execution of the command and as such
	// it will not count towards the amount if it is set. It will also not
	// reschedule Next if this is set to a different command.
	CondFunc func() bool
	// contains filtered or unexported fields
}

type Scheduler

type Scheduler struct {
	Client             *discord.Client
	Logger             *logrus.Logger
	ChannelID          string
	Typing             *config.Typing
	MessageDelay       *config.MessageDelay
	AwaitResumeTimeout time.Duration
	FatalHandler       func(err error)
	// contains filtered or unexported fields
}

func (*Scheduler) AwaitResumeTrigger

func (s *Scheduler) AwaitResumeTrigger() *Command

AwaitResumeTrigger returns the value of the command that caused the await resume state. An empty string will be returned if the scheduler is not awaiting a resume at the time this method is called.

func (*Scheduler) Close

func (s *Scheduler) Close() error

Close closes the scheduler.

func (*Scheduler) PrioritySchedule

func (s *Scheduler) PrioritySchedule(cmd *Command)

func (*Scheduler) Resume

func (s *Scheduler) Resume()

Resume makes a scheduler continue after being paused by a command with an AwaitResume value of true. Will block until scheduler has received the resume call.

func (*Scheduler) ResumeWithCommand

func (s *Scheduler) ResumeWithCommand(cmd *Command)

ResumeWithCommand is the same as Resume but executes the passed command immediately after resuming.

func (*Scheduler) ResumeWithCommandOrPrioritySchedule

func (s *Scheduler) ResumeWithCommandOrPrioritySchedule(cmd *Command)

ResumeWithCommandOrPrioritySchedule is the same as ResumeWithCommand, but if the scheduler is not awaiting a resume, it will schedule the command in the priority queue instead.

func (*Scheduler) Schedule

func (s *Scheduler) Schedule(cmd *Command)

func (*Scheduler) Start

func (s *Scheduler) Start() error

Jump to

Keyboard shortcuts

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