cmdqueue

package
v0.0.0-...-9648343 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package cmdqueue implements a command queueing and execution management system.

Fundamental assumptions:

  • We are always ready to accept at least one queued command per channel, for all channels serviced by this instance.

Channel considerations:

- Command acceptance is subject to:

  • Batch-capable commands

  • Command-handler is fast and execution is serialized (no parallel calls for the same command)

  • Always accepted unconditionally

  • We take the hit on worst-case memory usage

  • Serialized commands

  • Async slow commands

- Command output is always rate-limited according to global parameters.

  • Command output is rate-limited to a 1-second minimum interval for channels, if the channel is not marked as exempt.

  • Ability to forcefully bypass.

Mode-switching required to maximize output rate? Use token-bucket for burst, then switch to simple limit-per-second while bucket refills + cooldown?

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CmdQueue

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

func New

func New() *CmdQueue

func (*CmdQueue) AddCommand

func (cq *CmdQueue) AddCommand(cmd Command)

AddCommand enqueues a user-issued command.

func (*CmdQueue) CooldownChannel

func (cq *CmdQueue) CooldownChannel(channel string, delay time.Duration)

func (*CmdQueue) Exec

func (cq *CmdQueue) Exec(ctx context.Context)

Exec executes the command queue until the given context is done.

func (*CmdQueue) RemoveChannel

func (cq *CmdQueue) RemoveChannel(channel string)

RemoveChannel clears channel state after a PART.

func (*CmdQueue) SetKey

func (cq *CmdQueue) SetKey(channel, user, key string, cd int)

SetKey sets a cooldown key for a specific channel.

type Command

type Command struct {
	ChanCD, UserCD int
	Channel, User  string
	CooldownMode   int
	Time           time.Time

	Action func() bool
	Async  bool

	CooldownKey string
	CommandCD   time.Duration

	Debug string
}

A Command contains all information relevant for the execution of one command.

Jump to

Keyboard shortcuts

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