jobrunner

package
v0.0.0-...-191742e Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: AGPL-3.0 Imports: 15 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) (*string, error)

Sets up a job

func Execute

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

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 redis temporarily

Types

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 State

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

type State

type State struct {
	Ctx context.Context
}

Implementor of jobs.State

func (State) Context

func (t State) Context() context.Context

func (State) DebugInfo

func (State) DebugInfo() *debug.BuildInfo

func (State) Discord

func (State) Discord() (*discordgo.Session, *discordgo.User, bool)

func (State) OperationMode

func (State) OperationMode() string

func (State) Transport

func (State) Transport() *http.Transport

Jump to

Keyboard shortcuts

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