store

package
v0.0.0-...-557f3cc Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a requested record does not exist.

Functions

This section is empty.

Types

type PoolStats

type PoolStats struct {
	AcquiredConns int32
	IdleConns     int32
	TotalConns    int32
	MaxConns      int32
}

PoolStats holds a snapshot of connection pool statistics.

type PostgresStore

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

PostgresStore implements Store using pgxpool.

func NewPostgres

func NewPostgres(ctx context.Context, databaseURL string, migrationsDir string) (*PostgresStore, error)

NewPostgres connects to a Postgres database, runs goose migrations, and returns a ready-to-use PostgresStore.

func (*PostgresStore) AssignTask

func (s *PostgresStore) AssignTask(ctx context.Context, id string, instanceID string) error

func (*PostgresStore) CancelTask

func (s *PostgresStore) CancelTask(ctx context.Context, id string) error

func (*PostgresStore) ClearTaskAssignment

func (s *PostgresStore) ClearTaskAssignment(ctx context.Context, id string) error

func (*PostgresStore) Close

func (s *PostgresStore) Close() error

func (*PostgresStore) CompleteTask

func (s *PostgresStore) CompleteTask(ctx context.Context, id string, result TaskResult) error

func (*PostgresStore) CreateAPIKey

func (s *PostgresStore) CreateAPIKey(ctx context.Context, key *models.APIKey) error

func (*PostgresStore) CreateAllowedSender

func (s *PostgresStore) CreateAllowedSender(ctx context.Context, sender *models.AllowedSender) error

func (*PostgresStore) CreateInstance

func (s *PostgresStore) CreateInstance(ctx context.Context, inst *models.Instance) error

func (*PostgresStore) CreateTask

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

func (*PostgresStore) DecrementRunningContainers

func (s *PostgresStore) DecrementRunningContainers(ctx context.Context, id string) error

func (*PostgresStore) DeleteDiscordInstall

func (s *PostgresStore) DeleteDiscordInstall(ctx context.Context, guildID string) error

func (*PostgresStore) DeleteTask

func (s *PostgresStore) DeleteTask(ctx context.Context, id string) error

func (*PostgresStore) GetAPIKeyByHash

func (s *PostgresStore) GetAPIKeyByHash(ctx context.Context, keyHash string) (*models.APIKey, error)

func (*PostgresStore) GetAllowedSender

func (s *PostgresStore) GetAllowedSender(ctx context.Context, channelType, address string) (*models.AllowedSender, error)

func (*PostgresStore) GetDiscordInstall

func (s *PostgresStore) GetDiscordInstall(ctx context.Context, guildID string) (*models.DiscordInstall, error)

func (*PostgresStore) GetDiscordTaskThread

func (s *PostgresStore) GetDiscordTaskThread(ctx context.Context, taskID string) (*models.DiscordTaskThread, error)

func (*PostgresStore) GetInstance

func (s *PostgresStore) GetInstance(ctx context.Context, id string) (*models.Instance, error)

func (*PostgresStore) GetReadingByURL

func (s *PostgresStore) GetReadingByURL(ctx context.Context, url string) (*models.Reading, error)

GetReadingByURL returns the reading row whose url column matches exactly. Returns ErrNotFound when no row matches. The embedding column is intentionally not selected — callers that need it should fetch by id with a dedicated query.

func (*PostgresStore) GetTask

func (s *PostgresStore) GetTask(ctx context.Context, id string) (*models.Task, error)

func (*PostgresStore) HasAPIKeys

func (s *PostgresStore) HasAPIKeys(ctx context.Context) (bool, error)

func (*PostgresStore) IncrementRunningContainers

func (s *PostgresStore) IncrementRunningContainers(ctx context.Context, id string) error

func (*PostgresStore) ListInstances

func (s *PostgresStore) ListInstances(ctx context.Context, status *models.InstanceStatus) ([]*models.Instance, error)

func (*PostgresStore) ListTasks

func (s *PostgresStore) ListTasks(ctx context.Context, filter TaskFilter) ([]*models.Task, error)

func (*PostgresStore) MarkReadyForRetry

func (s *PostgresStore) MarkReadyForRetry(ctx context.Context, id string) error

func (*PostgresStore) PoolStats

func (s *PostgresStore) PoolStats() PoolStats

PoolStats returns a snapshot of the underlying connection pool statistics.

func (*PostgresStore) RequeueTask

func (s *PostgresStore) RequeueTask(ctx context.Context, id string, reason string) error

func (*PostgresStore) ResetRunningContainers

func (s *PostgresStore) ResetRunningContainers(ctx context.Context, id string) error

func (*PostgresStore) RetryTask

func (s *PostgresStore) RetryTask(ctx context.Context, id string, maxRetries int) error

RetryTask atomically requeues a task for user-initiated retry. It checks ready_for_retry=true and user_retry_count < maxRetries in the WHERE clause to prevent retries before cleanup and double-retries. Returns ErrNotFound if no row matched (task not ready or cap reached).

func (*PostgresStore) StartTask

func (s *PostgresStore) StartTask(ctx context.Context, id string, containerID string) error

func (*PostgresStore) UpdateInstanceDetails

func (s *PostgresStore) UpdateInstanceDetails(ctx context.Context, id string, privateIP, az string) error

func (*PostgresStore) UpdateInstanceStatus

func (s *PostgresStore) UpdateInstanceStatus(ctx context.Context, id string, status models.InstanceStatus) error

func (*PostgresStore) UpdateTaskStatus

func (s *PostgresStore) UpdateTaskStatus(ctx context.Context, id string, status models.TaskStatus, taskErr string) error

func (*PostgresStore) UpsertDiscordInstall

func (s *PostgresStore) UpsertDiscordInstall(ctx context.Context, install *models.DiscordInstall) error

func (*PostgresStore) UpsertDiscordTaskThread

func (s *PostgresStore) UpsertDiscordTaskThread(ctx context.Context, thread *models.DiscordTaskThread) error

func (*PostgresStore) UpsertReading

func (s *PostgresStore) UpsertReading(ctx context.Context, r *models.Reading) error

func (*PostgresStore) WithTx

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

type Store

type Store interface {
	// Tasks
	CreateTask(ctx context.Context, task *models.Task) error
	GetTask(ctx context.Context, id string) (*models.Task, error)
	ListTasks(ctx context.Context, filter TaskFilter) ([]*models.Task, error)
	DeleteTask(ctx context.Context, id string) error

	// Named task updates
	UpdateTaskStatus(ctx context.Context, id string, status models.TaskStatus, taskErr string) error
	AssignTask(ctx context.Context, id string, instanceID string) error
	StartTask(ctx context.Context, id string, containerID string) error
	CompleteTask(ctx context.Context, id string, result TaskResult) error
	RequeueTask(ctx context.Context, id string, reason string) error
	CancelTask(ctx context.Context, id string) error
	ClearTaskAssignment(ctx context.Context, id string) error
	MarkReadyForRetry(ctx context.Context, id string) error
	RetryTask(ctx context.Context, id string, maxRetries int) error

	// Instances
	CreateInstance(ctx context.Context, inst *models.Instance) error
	GetInstance(ctx context.Context, id string) (*models.Instance, error)
	ListInstances(ctx context.Context, status *models.InstanceStatus) ([]*models.Instance, error)

	// Named instance updates
	UpdateInstanceStatus(ctx context.Context, id string, status models.InstanceStatus) error
	IncrementRunningContainers(ctx context.Context, id string) error
	DecrementRunningContainers(ctx context.Context, id string) error
	UpdateInstanceDetails(ctx context.Context, id string, privateIP, az string) error
	ResetRunningContainers(ctx context.Context, id string) error

	// Allowed senders
	GetAllowedSender(ctx context.Context, channelType, address string) (*models.AllowedSender, error)
	CreateAllowedSender(ctx context.Context, sender *models.AllowedSender) error

	// Discord installs
	UpsertDiscordInstall(ctx context.Context, install *models.DiscordInstall) error
	GetDiscordInstall(ctx context.Context, guildID string) (*models.DiscordInstall, error)
	DeleteDiscordInstall(ctx context.Context, guildID string) error

	// Discord task threads
	UpsertDiscordTaskThread(ctx context.Context, thread *models.DiscordTaskThread) error
	GetDiscordTaskThread(ctx context.Context, taskID string) (*models.DiscordTaskThread, error)

	// API keys
	HasAPIKeys(ctx context.Context) (bool, error)
	GetAPIKeyByHash(ctx context.Context, keyHash string) (*models.APIKey, error)
	CreateAPIKey(ctx context.Context, key *models.APIKey) error

	// Readings
	UpsertReading(ctx context.Context, r *models.Reading) error
	GetReadingByURL(ctx context.Context, url string) (*models.Reading, error)

	// Transactions
	WithTx(ctx context.Context, fn func(Store) error) error

	Close() error
}

Store is the persistence interface for tasks and instances.

type TaskFilter

type TaskFilter struct {
	Status *models.TaskStatus
	Limit  int
	Offset int
}

TaskFilter controls listing behavior.

type TaskResult

type TaskResult struct {
	Status         models.TaskStatus
	Error          string
	PRURL          string
	OutputURL      string
	CostUSD        float64
	ElapsedTimeSec int
	RepoURL        string
	TargetBranch   string
	TaskMode       string
}

TaskResult holds the fields set when a task finishes (completed or failed).

Jump to

Keyboard shortcuts

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