jobrunner

package
v0.0.0-...-792b534 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package executor defines a "production-ready" executor for jobs.

For local/non-production use, consider looking at cmd/localjobs's executor

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, pool *pgxpool.Pool, jobImpl interfaces.JobImpl, guildId string) (*string, error)

Sets up a job

func Execute

func Execute(
	ctx context.Context,
	ctxCancel context.CancelFunc,
	id string,
	jobImpl interfaces.JobImpl,
	prog *Progress,
	guildId string,
)

Creates a new job on server and executes it

If prog is set, it will be used to cache the progress, otherwise a blank one will be used

func GetPersistedState

func GetPersistedState(tc *Progress) (*jobstate.Progress, error)

GetPersistedState gets persisted state from redis

func PersistState

func PersistState(tc *Progress, prog *jobstate.Progress) error

PersistState persists the state to postgres temporarily

Types

type JobrunnerState

type JobrunnerState struct {
	Ctx     context.Context
	GuildId string
}

Implementor of jobs.State

func (JobrunnerState) Context

func (t JobrunnerState) Context() context.Context

func (JobrunnerState) DebugInfo

func (JobrunnerState) DebugInfo() *debug.BuildInfo

func (JobrunnerState) Discord

func (JobrunnerState) GuildID

func (t JobrunnerState) GuildID() string

func (JobrunnerState) OperationMode

func (JobrunnerState) OperationMode() string

func (JobrunnerState) Transport

func (j JobrunnerState) Transport() *http.Transport

type MutLogger

type MutLogger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewTaskLogger

func NewTaskLogger(id string, pool *pgxpool.Pool, ctx context.Context, baseLogger *zap.Logger) (*zap.Logger, *MutLogger)

func (*MutLogger) Sync

func (m *MutLogger) Sync() error

func (*MutLogger) Write

func (m *MutLogger) Write(p []byte) (n int, err error)

type Progress

type Progress struct {
	ID string

	State JobrunnerState

	// Used to cache the current progress in resumes
	//
	// When resuming, set this to the current progress
	CurrentProgress *jobstate.Progress

	// OnSetProgress is a callback that is called when SetProgress is called
	//
	// If unset, calls PersistState
	OnSetProgress func(tc *Progress, prog *jobstate.Progress) error
}

func (Progress) GetProgress

func (ts Progress) GetProgress() (*jobstate.Progress, error)

func (Progress) SetProgress

func (ts Progress) SetProgress(prog *jobstate.Progress) error

Jump to

Keyboard shortcuts

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