store

package
v1.4.2 Latest Latest
Warning

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

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

Documentation

Overview

Package store provides the storage layer for task and operation rule management. It defines the Store interface for persisting and retrieving task and operation rule data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PostgresStore

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

PostgresStore implements the Store interface using PostgreSQL.

func NewPostgres

func NewPostgres(pg *cdb.Session) *PostgresStore

NewPostgres creates a new PostgreSQL-backed task store.

func (*PostgresStore) AssociateRuleWithRack

func (s *PostgresStore) AssociateRuleWithRack(
	ctx context.Context,
	rackID uuid.UUID,
	ruleID uuid.UUID,
) error

AssociateRuleWithRack associates a rule with a rack. The operation type and operation code are extracted from the rule.

func (*PostgresStore) CountWaitingTasksForRack

func (s *PostgresStore) CountWaitingTasksForRack(
	ctx context.Context,
	rackID uuid.UUID,
) (int, error)

CountWaitingTasksForRack returns the count of waiting tasks for the rack.

func (*PostgresStore) CreateRule

func (s *PostgresStore) CreateRule(
	ctx context.Context,
	rule *operationrules.OperationRule,
) error

CreateRule creates a new operation rule

func (*PostgresStore) CreateTask

func (s *PostgresStore) CreateTask(
	ctx context.Context,
	task *taskdef.Task,
) error

CreateTask creates a new task record. Participates in a surrounding transaction if one was started by RunInTransaction.

func (*PostgresStore) DeleteRule

func (s *PostgresStore) DeleteRule(
	ctx context.Context,
	id uuid.UUID,
) error

DeleteRule deletes an operation rule by ID

func (*PostgresStore) DisassociateRuleFromRack

func (s *PostgresStore) DisassociateRuleFromRack(
	ctx context.Context,
	rackID uuid.UUID,
	opType taskcommon.TaskType,
	operationCode string,
) error

DisassociateRuleFromRack removes the rule association for a rack, operation type, and operation code

func (*PostgresStore) GetDefaultRule

func (s *PostgresStore) GetDefaultRule(
	ctx context.Context,
	opType taskcommon.TaskType,
	operationCode string,
) (*operationrules.OperationRule, error)

GetDefaultRule retrieves the default rule for an operation type and code

func (*PostgresStore) GetRackRuleAssociation

func (s *PostgresStore) GetRackRuleAssociation(
	ctx context.Context,
	rackID uuid.UUID,
	opType taskcommon.TaskType,
	operationCode string,
) (*uuid.UUID, error)

GetRackRuleAssociation retrieves the rule ID associated with a rack for an operation type and operation code

func (*PostgresStore) GetRule

GetRule retrieves an operation rule by ID

func (*PostgresStore) GetRuleByName

func (s *PostgresStore) GetRuleByName(
	ctx context.Context,
	name string,
) (*operationrules.OperationRule, error)

GetRuleByName retrieves an operation rule by its name

func (*PostgresStore) GetRuleByOperationAndRack

func (s *PostgresStore) GetRuleByOperationAndRack(
	ctx context.Context,
	opType taskcommon.TaskType,
	operationCode string,
	rackID *uuid.UUID,
) (*operationrules.OperationRule, error)

GetRuleByOperationAndRack retrieves the appropriate rule for an operation code and rack. Resolution order: rack association > default rule

func (*PostgresStore) GetTask

func (s *PostgresStore) GetTask(
	ctx context.Context,
	id uuid.UUID,
) (*taskdef.Task, error)

GetTask retrieves a single task by its ID.

func (*PostgresStore) GetTasks

func (s *PostgresStore) GetTasks(
	ctx context.Context,
	ids []uuid.UUID,
) ([]*taskdef.Task, error)

GetTasks retrieves tasks by their IDs.

func (*PostgresStore) ListActiveTasksForRack

func (s *PostgresStore) ListActiveTasksForRack(
	ctx context.Context,
	rackID uuid.UUID,
) ([]*taskdef.Task, error)

ListActiveTasksForRack returns pending and running tasks for the given rack.

func (*PostgresStore) ListRackRuleAssociations

func (s *PostgresStore) ListRackRuleAssociations(
	ctx context.Context,
	rackID uuid.UUID,
) ([]*operationrules.RackRuleAssociation, error)

ListRackRuleAssociations retrieves all rule associations for a rack

func (*PostgresStore) ListRacksWithWaitingTasks

func (s *PostgresStore) ListRacksWithWaitingTasks(
	ctx context.Context,
) ([]uuid.UUID, error)

ListRacksWithWaitingTasks returns distinct rack IDs with waiting tasks.

func (*PostgresStore) ListRules

ListRules lists operation rules matching the given criteria with pagination

func (*PostgresStore) ListTasks

func (s *PostgresStore) ListTasks(
	ctx context.Context,
	options *taskcommon.TaskListOptions,
	pagination *dbquery.Pagination,
) ([]*taskdef.Task, int32, error)

ListTasks lists tasks matching the given criteria.

func (*PostgresStore) ListWaitingTasksForRack

func (s *PostgresStore) ListWaitingTasksForRack(
	ctx context.Context,
	rackID uuid.UUID,
) ([]*taskdef.Task, error)

ListWaitingTasksForRack returns waiting tasks for the rack, oldest first.

func (*PostgresStore) RunInTransaction

func (s *PostgresStore) RunInTransaction(
	ctx context.Context,
	fn func(ctx context.Context) error,
) error

RunInTransaction executes fn within a database transaction, propagating the transaction through the context so nested store calls participate.

func (*PostgresStore) SetRuleAsDefault

func (s *PostgresStore) SetRuleAsDefault(
	ctx context.Context,
	id uuid.UUID,
) error

SetRuleAsDefault sets a rule as the default for its operation. Automatically unsets any existing default for the same (operation_type, operation_code).

func (*PostgresStore) UpdateRule

func (s *PostgresStore) UpdateRule(
	ctx context.Context,
	id uuid.UUID,
	updates map[string]interface{},
) error

UpdateRule updates specific fields of an operation rule

func (*PostgresStore) UpdateScheduledTask

func (s *PostgresStore) UpdateScheduledTask(
	ctx context.Context,
	task *taskdef.Task,
) error

UpdateScheduledTask updates task scheduling information.

func (*PostgresStore) UpdateTaskStatus

func (s *PostgresStore) UpdateTaskStatus(
	ctx context.Context,
	arg *taskdef.TaskStatusUpdate,
) error

UpdateTaskStatus updates the status and message of a task.

type Store

type Store interface {

	// RunInTransaction executes fn within a database transaction.
	// The transaction is propagated through the context so that nested store
	// calls automatically participate without extra plumbing.
	RunInTransaction(ctx context.Context, fn func(ctx context.Context) error) error

	// CreateTask creates a new task record.
	CreateTask(ctx context.Context, task *taskdef.Task) error

	// GetTask retrieves a single task by its ID.
	// Returns an error if the task is not found.
	GetTask(ctx context.Context, id uuid.UUID) (*taskdef.Task, error)

	// GetTasks retrieves tasks by their IDs.
	GetTasks(ctx context.Context, ids []uuid.UUID) ([]*taskdef.Task, error)

	// ListTasks lists tasks matching the given criteria.
	ListTasks(ctx context.Context, options *taskcommon.TaskListOptions, pagination *dbquery.Pagination) ([]*taskdef.Task, int32, error)

	// UpdateScheduledTask updates task scheduling information (execution ID, executor type).
	UpdateScheduledTask(ctx context.Context, task *taskdef.Task) error

	// UpdateTaskStatus updates the status and message of a task.
	UpdateTaskStatus(ctx context.Context, arg *taskdef.TaskStatusUpdate) error

	// ListActiveTasksForRack returns non-finished, non-waiting tasks for a rack
	// (i.e. tasks with status pending or running).
	ListActiveTasksForRack(ctx context.Context, rackID uuid.UUID) ([]*taskdef.Task, error)

	// ListWaitingTasksForRack returns waiting tasks for a rack, ordered oldest-first.
	ListWaitingTasksForRack(ctx context.Context, rackID uuid.UUID) ([]*taskdef.Task, error)

	// CountWaitingTasksForRack returns the number of waiting tasks for a rack.
	CountWaitingTasksForRack(ctx context.Context, rackID uuid.UUID) (int, error)

	// ListRacksWithWaitingTasks returns distinct rack IDs that have at least
	// one task in the waiting state.
	ListRacksWithWaitingTasks(ctx context.Context) ([]uuid.UUID, error)

	// CreateRule creates a new operation rule.
	CreateRule(ctx context.Context, rule *operationrules.OperationRule) error

	// UpdateRule updates specific fields of an operation rule.
	UpdateRule(ctx context.Context, id uuid.UUID, updates map[string]interface{}) error

	// DeleteRule deletes an operation rule by ID.
	DeleteRule(ctx context.Context, id uuid.UUID) error

	// SetRuleAsDefault sets a rule as the default for its operation.
	// Automatically unsets any existing default for the same (operation_type, operation).
	SetRuleAsDefault(ctx context.Context, id uuid.UUID) error

	// GetRule retrieves an operation rule by ID.
	GetRule(ctx context.Context, id uuid.UUID) (*operationrules.OperationRule, error)

	// GetRuleByName retrieves an operation rule by its name.
	GetRuleByName(ctx context.Context, name string) (*operationrules.OperationRule, error)

	// GetDefaultRule retrieves the default rule for an operation type and operation code.
	// Returns the rule with is_default=true for the given operation type and operation code.
	GetDefaultRule(ctx context.Context, opType taskcommon.TaskType, operationCode string) (*operationrules.OperationRule, error)

	// GetRuleByOperationAndRack retrieves the appropriate rule for an operation type, operation code, and rack.
	// Resolution order: rack association > default rule
	// If rackID is nil, returns the default rule.
	GetRuleByOperationAndRack(ctx context.Context, opType taskcommon.TaskType, operationCode string, rackID *uuid.UUID) (*operationrules.OperationRule, error)

	// ListRules lists operation rules matching the given criteria with pagination.
	ListRules(ctx context.Context, options *taskcommon.OperationRuleListOptions, pagination *dbquery.Pagination) ([]*operationrules.OperationRule, int32, error)

	// AssociateRuleWithRack associates a rule with a rack.
	// The operation type and operation code are extracted from the rule.
	// If an association already exists, it will be updated.
	AssociateRuleWithRack(ctx context.Context, rackID uuid.UUID, ruleID uuid.UUID) error

	// DisassociateRuleFromRack removes the rule association for a rack, operation type, and operation code.
	DisassociateRuleFromRack(ctx context.Context, rackID uuid.UUID, opType taskcommon.TaskType, operationCode string) error

	// GetRackRuleAssociation retrieves the rule ID associated with a rack for an operation type and operation code.
	// Returns nil if no association exists.
	GetRackRuleAssociation(ctx context.Context, rackID uuid.UUID, opType taskcommon.TaskType, operationCode string) (*uuid.UUID, error)

	// ListRackRuleAssociations retrieves all rule associations for a rack.
	// Returns a list of associations with full details (operation type, operation code, rule ID).
	ListRackRuleAssociations(ctx context.Context, rackID uuid.UUID) ([]*operationrules.RackRuleAssociation, error)
}

Store defines the interface for task and operation rule data persistence. It provides operations for creating, retrieving, and updating both tasks and operation rules.

Jump to

Keyboard shortcuts

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