jobrunner

package
v0.0.0-...-13da7ca Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package taskexecutor defines a "production-ready" task executor.

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTask

func CreateTask(ctx context.Context, pool *pgxpool.Pool, task taskdef.TaskDefinition) (*string, error)

Sets up a task

func ExecuteTask

func ExecuteTask(
	ctx context.Context,
	ctxCancel context.CancelFunc,
	taskId string,
	task taskdef.TaskDefinition,
	prog *TaskProgress,
)

Creates a new task on server and executes it

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

func GetPersistedTaskState

func GetPersistedTaskState(tc *TaskProgress) (*taskstate.Progress, error)

GetPersistedTaskState gets persisted task state from redis

func PersistTaskState

func PersistTaskState(tc *TaskProgress, prog *taskstate.Progress) error

PersistTaskState persists task state to redis temporarily

Types

type MutLogger

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

func NewTaskLogger

func NewTaskLogger(taskId 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 TaskProgress

type TaskProgress struct {
	TaskID string

	TaskState TaskState

	// Used to cache the current task progress in resumes
	//
	// When resuming, set this to the current progress
	CurrentTaskProgress *taskstate.Progress

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

func (TaskProgress) GetProgress

func (ts TaskProgress) GetProgress() (*taskstate.Progress, error)

func (TaskProgress) SetProgress

func (ts TaskProgress) SetProgress(prog *taskstate.Progress) error

type TaskState

type TaskState struct {
	Ctx context.Context
}

Implementor of tasks.TaskState

func (TaskState) Context

func (t TaskState) Context() context.Context

func (TaskState) DebugInfo

func (TaskState) DebugInfo() *debug.BuildInfo

func (TaskState) Discord

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

func (TaskState) OperationMode

func (TaskState) OperationMode() string

func (TaskState) Transport

func (TaskState) Transport() *http.Transport

Jump to

Keyboard shortcuts

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