task

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultArgsField = "args"
View Source
const DefaultCreatedAtField = "created_at"
View Source
const DefaultErrorField = "error"
View Source
const DefaultFinishedAtField = "finished_at"
View Source
const DefaultFuncField = "func"
View Source
const DefaultIdField = "id"
View Source
const DefaultIsProcessedField = "is_processed"
View Source
const DefaultIsSuccessField = "is_success_flg"
View Source
const DefaultResultField = "result"
View Source
const DefaultStartedAtField = "started_at"
View Source
const DefaultTableName = "barn_task"

Variables

This section is empty.

Functions

This section is empty.

Types

type PostgresTaskRepository added in v0.3.1

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

func (*PostgresTaskRepository) Create added in v0.3.1

func (r *PostgresTaskRepository) Create(tx *sql.Tx, t *Task) error

func (*PostgresTaskRepository) CreateTable added in v0.3.1

func (r *PostgresTaskRepository) CreateTable(tx *sql.Tx) error

func (*PostgresTaskRepository) DeleteAll added in v0.3.1

func (r *PostgresTaskRepository) DeleteAll(tx *sql.Tx) error

func (*PostgresTaskRepository) DeleteOld added in v0.3.1

func (r *PostgresTaskRepository) DeleteOld(tx *sql.Tx, moment time.Time) (int, error)

func (*PostgresTaskRepository) FindNext added in v0.3.1

func (r *PostgresTaskRepository) FindNext(tx *sql.Tx) (*Task, error)

func (*PostgresTaskRepository) Save added in v0.3.1

func (r *PostgresTaskRepository) Save(tx *sql.Tx, t *Task) error

type Status

type Status uint8

type Task

type Task struct {
	Id          int
	CreatedAt   time.Time
	Func        string
	Args        any
	IsProcessed bool
	StartedAt   *time.Time
	FinishedAt  *time.Time
	IsSuccess   *bool
	Result      any
	Error       *string
}

func (Task) LogValue

func (e Task) LogValue() slog.Value

type TaskHandler

type TaskHandler func(tx *sql.Tx, task *Task) error

type TaskQueryConfig

type TaskQueryConfig struct {
	TableName        string
	IdField          string
	CreatedAtField   string
	FuncField        string
	ArgsField        string
	IsProcessedField string
	StartedAtField   string
	FinishedAtField  string
	IsSuccessField   string
	ResultField      string
	ErrorField       string
}

type TaskRepository

type TaskRepository interface {
	FindNext(tx *sql.Tx) (*Task, error)
	Create(tx *sql.Tx, task *Task) error
	Save(tx *sql.Tx, task *Task) error
	DeleteOld(tx *sql.Tx, t time.Time) (int, error)
}

func NewPostgresTaskRepository added in v0.3.1

func NewPostgresTaskRepository(config ...TaskQueryConfig) TaskRepository

type Worker

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

func NewWorker

func NewWorker(db *sql.DB, config *WorkerConfig) *Worker

func (*Worker) Start

func (w *Worker) Start()

func (*Worker) StartContext

func (w *Worker) StartContext(ctx context.Context)

func (*Worker) Stop

func (w *Worker) Stop()

type WorkerConfig

type WorkerConfig struct {
	Log        *slog.Logger
	Repository TaskRepository
	Cron       string
	Handler    TaskHandler
}

Jump to

Keyboard shortcuts

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