async

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLoadingDatabaseHost = errors.New("error loading task queue host")
	ErrMTLSRedisClientOpt  = errors.New("error redis client opt")
	ErrSecretTypeQueue     = errors.New("unsupported secret type for task queue")
	ErrACLNotEnabled       = errors.New("ACL is not enabled for task queue")
	ErrACLPassword         = errors.New("ACL is not load password for redis client")
	ErrACLUsername         = errors.New("ACL is not load username for redis client")
)
View Source
var (
	ErrEnqueueingTask    = errors.New("enqueue task")
	ErrClientShutdown    = errors.New("client shutdown")
	ErrStartingWorker    = errors.New("starting worker")
	ErrCreatingScheduler = errors.New("creating scheduler")
	ErrRunningScheduler  = errors.New("running scheduler")
	ErrReadingConfig     = errors.New("error reading scheduler task config file")
	ErrInvalidConfig     = errors.New("invalid scheduler task config")
	ErrNilTask           = errors.New("task is nil")
)

Functions

func FanOutTask added in v0.8.0

func FanOutTask(
	ctx context.Context,
	asyncClient Client,
	parentTask *asynq.Task,
	payload asyncUtils.TaskPayload,
	opts ...asynq.Option,
) error

FanOutTask enqueues a child task for a task This is used to allow parallelism on tasks running in a loop manner Example of it's usage is for example in the ProcessTenantsInBatch to spawn a task for each tenant

func TenantFanOut added in v0.8.0

func TenantFanOut(ctx context.Context, task *asynq.Task, f ProcessFunc) error

TenantFanOut extracts tenant from payload and injects it into context before executing

func TracingMiddleware added in v0.7.0

func TracingMiddleware(cfg config.Config) func(next asynq.HandlerFunc) asynq.HandlerFunc

Types

type App

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

func New

func New(cfg *conf.Config) (*App, error)

New creates a new instance of App

func (*App) Client

func (a *App) Client() *asynq.Client

func (*App) Enqueue

func (a *App) Enqueue(
	ctx context.Context,
	task *asynq.Task,
	opts ...asynq.Option,
) (*asynq.TaskInfo, error)

Enqueue is used to run tasks

func (*App) Inspector

func (a *App) Inspector() *asynq.Inspector

func (*App) RegisterTasks

func (a *App) RegisterTasks(ctx context.Context, handlers []TaskHandler)

RegisterTasks registers multiple task handlers

func (*App) RunScheduler

func (a *App) RunScheduler() error

RunScheduler starts the cron job scheduling It starts the cron related tasks defined in the schedulerTasksConfig

func (*App) RunWorker

func (a *App) RunWorker(ctx context.Context, r repo.Repo) error

RunWorker starts the worker process to process the tasks

func (*App) Shutdown

func (a *App) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the worker and scheduler

type BatchProcessor added in v0.8.0

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

func NewBatchProcessor added in v0.8.0

func NewBatchProcessor(r repo.Repo, opts ...BatchProcessorOptions) *BatchProcessor

func (*BatchProcessor) ProcessTenantsInBatch added in v0.8.0

func (bp *BatchProcessor) ProcessTenantsInBatch(
	ctx context.Context,
	asynqTask *asynq.Task,
	processTenant func(ctx context.Context, task *asynq.Task) error,
) error

ProcessTenantsInBatch iterates through tenants in batches and applies the process function It tracks the total tenant count, logs batch progress, and logs task completion In fan-out mode, it enqueues child tasks instead of processing inline

type BatchProcessorOptions added in v0.8.0

type BatchProcessorOptions func(*BatchProcessor)

func WithFanOutTenants added in v0.8.0

func WithFanOutTenants(asyncClient Client, opts ...asynq.Option) BatchProcessorOptions

func WithTenantQuery added in v0.8.0

func WithTenantQuery(q *repo.Query) BatchProcessorOptions

type ChildTaskHandler added in v0.8.0

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

ChildTaskHandler wraps a parent handler and executes its ProcessTask with custom fanout logic

func NewFanOutHandler added in v0.8.0

func NewFanOutHandler(
	parent TaskHandler,
	fanOutFunc func(ctx context.Context, task *asynq.Task, f ProcessFunc) error,
) *ChildTaskHandler

func (*ChildTaskHandler) IsFanOutEnabled added in v0.8.0

func (c *ChildTaskHandler) IsFanOutEnabled() bool

IsFanOutEnabled returns false for child tasks

func (*ChildTaskHandler) ProcessTask added in v0.8.0

func (c *ChildTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task) error

func (*ChildTaskHandler) TaskType added in v0.8.0

func (c *ChildTaskHandler) TaskType() string

type Client

type Client interface {
	Close() error
	Enqueue(task *asynq.Task, opts ...asynq.Option) (*asynq.TaskInfo, error)
	EnqueueContext(ctx context.Context, task *asynq.Task, opts ...asynq.Option) (*asynq.TaskInfo, error)
	Ping() error
}

type FanOutFunc added in v0.8.0

type FanOutFunc func(ctx context.Context, task *asynq.Task, f ProcessFunc) error

type FanOutHandler added in v0.8.0

type FanOutHandler interface {
	TaskHandler

	FanOutFunc() FanOutFunc
}

FanOutHandler task into child tasks per tenant

type Middleware added in v0.7.0

type Middleware func(asynq.HandlerFunc) asynq.HandlerFunc

type MockClient

type MockClient struct {
	EnqueueCallCount int
	LastTask         *asynq.Task
	Error            error
}

MockClient implements the AsyncClient interface for testing

func (*MockClient) Close

func (m *MockClient) Close() error

func (*MockClient) Enqueue

func (m *MockClient) Enqueue(task *asynq.Task, opt ...asynq.Option) (*asynq.TaskInfo, error)

func (*MockClient) EnqueueContext

func (m *MockClient) EnqueueContext(_ context.Context, task *asynq.Task, opt ...asynq.Option) (*asynq.TaskInfo, error)

func (*MockClient) Ping

func (m *MockClient) Ping() error

type ProcessFunc added in v0.8.0

type ProcessFunc func(ctx context.Context, task *asynq.Task) error

type ScheduledTaskConfigProvider

type ScheduledTaskConfigProvider struct {
	Config *config.Config
}

ScheduledTaskConfigProvider implements asynq PeriodicTaskConfigProvider interface.

func (*ScheduledTaskConfigProvider) GetConfigs

GetConfigs Parses the yaml file and return a list of PeriodicTaskConfigs.

type TaskHandler

type TaskHandler interface {
	ProcessTask(ctx context.Context, task *asynq.Task) error
	TaskType() string
}

TaskHandler defines the interface for handling async

type TaskOption added in v0.8.0

type TaskOption func(TenantTaskHandler)

type TenantTaskHandler added in v0.8.0

type TenantTaskHandler interface {
	TaskHandler
	FanOutHandler

	TenantQuery() *repo.Query
}

TenantTaskHandler is a task that is run for a selection of tenants

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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