tasks

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: GPL-3.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tasks provides task handling and execution functionality

Index

Constants

View Source
const (
	// DirectionForward represents forward fill processing
	DirectionForward = "forward"
	// DirectionBack represents backfill processing
	DirectionBack = "back"

	// ScanTypeIncremental is the incremental scan type for external models
	ScanTypeIncremental = "incremental"
	// ScanTypeFull is the full scan type for external models
	ScanTypeFull = "full"
)
View Source
const (
	// TypeModelTransformation is the task type for model transformations
	TypeModelTransformation = "model:transformation"
)

Variables

View Source
var (
	// ErrModelConfigNotFound is returned when model configuration is not found
	ErrModelConfigNotFound = errors.New("model configuration not found")
	// ErrDependenciesNotSatisfied is returned when dependencies are not satisfied
	ErrDependenciesNotSatisfied = errors.New("dependencies not satisfied")
	// ErrModelIDNotFound is returned when model_id is not found in payload
	ErrModelIDNotFound = errors.New("model_id not found in payload")
	// ErrScanTypeNotFound is returned when scan_type is not found in payload
	ErrScanTypeNotFound = errors.New("scan_type not found in payload")
	// ErrUnexpectedExternalType is returned when an external task type appears in transformation payload.
	ErrUnexpectedExternalType = errors.New("unexpected external task type in transformation payload")
)

Functions

This section is empty.

Types

type ExecutionContext added in v0.1.7

type ExecutionContext struct {
	Transformation models.Transformation
	Position       uint64
	Interval       uint64
	ExecutionTime  time.Time // Time the task should execute for (from payload or start time)
	StartTime      time.Time // When the handler started processing
	WorkerID       string
}

ExecutionContext contains all context needed for task execution

type Executor

type Executor interface {
	Execute(ctx context.Context, taskCtx *ExecutionContext) error
	Validate(ctx context.Context, taskCtx *ExecutionContext) error
	UpdateBounds(ctx context.Context, modelID, scanType string) error
}

Executor defines the interface for task executors

type Handler added in v0.1.7

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

Handler handles task execution

func NewHandler added in v0.1.7

func NewHandler(
	logger logrus.FieldLogger,
	chClient clickhouse.ClientInterface,
	adminService admin.Service,
	validator validation.Validator,
	modelExecutor Executor,
	transformations []models.Transformation,
) *Handler

NewHandler creates a new task handler

func (*Handler) HandleExternalScan added in v0.1.7

func (h *Handler) HandleExternalScan(ctx context.Context, t *asynq.Task) error

HandleExternalScan handles external model scan tasks (both incremental and full)

func (*Handler) HandleTransformation added in v0.1.7

func (h *Handler) HandleTransformation(ctx context.Context, t *asynq.Task) error

HandleTransformation handles transformation tasks

func (*Handler) Routes added in v0.1.7

func (h *Handler) Routes() map[string]asynq.HandlerFunc

Routes returns the task handler routes for Asynq

type IncrementalPayload added in v0.1.7

type IncrementalPayload struct {
	Type       Type      `json:"type"`
	ModelID    string    `json:"model_id"`
	Position   uint64    `json:"position"`
	Interval   uint64    `json:"interval"`
	Direction  string    `json:"direction"` // DirectionForward or DirectionBack
	EnqueuedAt time.Time `json:"enqueued_at"`
}

IncrementalPayload represents a position-based incremental task

func (IncrementalPayload) GetEnqueuedAt added in v0.1.7

func (p IncrementalPayload) GetEnqueuedAt() time.Time

GetEnqueuedAt returns the enqueued time

func (IncrementalPayload) GetModelID added in v0.1.7

func (p IncrementalPayload) GetModelID() string

GetModelID returns the model ID

func (IncrementalPayload) GetType added in v0.1.7

func (p IncrementalPayload) GetType() Type

GetType returns the task type

func (IncrementalPayload) QueueName added in v0.1.7

func (p IncrementalPayload) QueueName() string

QueueName returns the queue name for this task

func (IncrementalPayload) UniqueID added in v0.1.7

func (p IncrementalPayload) UniqueID() string

UniqueID returns a unique identifier for this task Uses model.id:direction to ensure only one task per direction can run at a time. This prevents duplicate work when intervals expand (e.g., model:100:25 -> model:100:50) and leverages the natural separation between forward fill (frontier) and backfill (historical gaps).

type Payload added in v0.1.7

type Payload interface {
	GetModelID() string
	GetEnqueuedAt() time.Time
	GetType() Type
	UniqueID() string
	QueueName() string
}

Payload is the common interface for all task payloads

type QueueManager

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

QueueManager manages task queuing

func NewQueueManager

func NewQueueManager(redisOpt *asynq.RedisClientOpt) *QueueManager

NewQueueManager creates a new queue manager

func (*QueueManager) Close

func (q *QueueManager) Close() error

Close closes the queue manager, releasing both the client and inspector.

func (*QueueManager) Enqueue added in v0.0.2

func (q *QueueManager) Enqueue(task *asynq.Task, opts ...asynq.Option) (*asynq.TaskInfo, error)

Enqueue enqueues a generic task

func (*QueueManager) EnqueueTransformation

func (q *QueueManager) EnqueueTransformation(payload Payload, opts ...asynq.Option) error

EnqueueTransformation enqueues a transformation task

func (*QueueManager) IsTaskPendingOrRunning

func (q *QueueManager) IsTaskPendingOrRunning(task Payload) (bool, error)

IsTaskPendingOrRunning checks if a task is pending or running

type ScheduledPayload added in v0.1.7

type ScheduledPayload struct {
	Type          Type      `json:"type"`
	ModelID       string    `json:"model_id"`
	ExecutionTime time.Time `json:"execution_time"`
	EnqueuedAt    time.Time `json:"enqueued_at"`
}

ScheduledPayload represents a scheduled cron-based task

func (ScheduledPayload) GetEnqueuedAt added in v0.1.7

func (p ScheduledPayload) GetEnqueuedAt() time.Time

GetEnqueuedAt returns the enqueued time

func (ScheduledPayload) GetModelID added in v0.1.7

func (p ScheduledPayload) GetModelID() string

GetModelID returns the model ID

func (ScheduledPayload) GetType added in v0.1.7

func (p ScheduledPayload) GetType() Type

GetType returns the task type

func (ScheduledPayload) QueueName added in v0.1.7

func (p ScheduledPayload) QueueName() string

QueueName returns the queue name for this task

func (ScheduledPayload) UniqueID added in v0.1.7

func (p ScheduledPayload) UniqueID() string

UniqueID returns a unique identifier for this task

type Type added in v0.1.7

type Type string

Type indicates whether this is a scheduled or incremental task

const (
	// TypeIncremental represents incremental position-based tasks
	TypeIncremental Type = "incremental"
	// TypeScheduled represents scheduled cron-based tasks
	TypeScheduled Type = "scheduled"
	// TypeExternal represents external model scan tasks
	TypeExternal Type = "external"
)

Jump to

Keyboard shortcuts

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