Documentation
¶
Index ¶
- Variables
- type PoolStats
- type PostgresStore
- func (s *PostgresStore) AssignTask(ctx context.Context, id string, instanceID string) error
- func (s *PostgresStore) CancelTask(ctx context.Context, id string) error
- func (s *PostgresStore) ClearTaskAssignment(ctx context.Context, id string) error
- func (s *PostgresStore) Close() error
- func (s *PostgresStore) CompleteTask(ctx context.Context, id string, result TaskResult) error
- func (s *PostgresStore) CreateAPIKey(ctx context.Context, key *models.APIKey) error
- func (s *PostgresStore) CreateAllowedSender(ctx context.Context, sender *models.AllowedSender) error
- func (s *PostgresStore) CreateInstance(ctx context.Context, inst *models.Instance) error
- func (s *PostgresStore) CreateTask(ctx context.Context, task *models.Task) error
- func (s *PostgresStore) DecrementRunningContainers(ctx context.Context, id string) error
- func (s *PostgresStore) DeleteDiscordInstall(ctx context.Context, guildID string) error
- func (s *PostgresStore) DeleteTask(ctx context.Context, id string) error
- func (s *PostgresStore) GetAPIKeyByHash(ctx context.Context, keyHash string) (*models.APIKey, error)
- func (s *PostgresStore) GetAllowedSender(ctx context.Context, channelType, address string) (*models.AllowedSender, error)
- func (s *PostgresStore) GetDiscordInstall(ctx context.Context, guildID string) (*models.DiscordInstall, error)
- func (s *PostgresStore) GetDiscordTaskThread(ctx context.Context, taskID string) (*models.DiscordTaskThread, error)
- func (s *PostgresStore) GetInstance(ctx context.Context, id string) (*models.Instance, error)
- func (s *PostgresStore) GetReadingByURL(ctx context.Context, url string) (*models.Reading, error)
- func (s *PostgresStore) GetTask(ctx context.Context, id string) (*models.Task, error)
- func (s *PostgresStore) HasAPIKeys(ctx context.Context) (bool, error)
- func (s *PostgresStore) IncrementRunningContainers(ctx context.Context, id string) error
- func (s *PostgresStore) ListInstances(ctx context.Context, status *models.InstanceStatus) ([]*models.Instance, error)
- func (s *PostgresStore) ListTasks(ctx context.Context, filter TaskFilter) ([]*models.Task, error)
- func (s *PostgresStore) MarkReadyForRetry(ctx context.Context, id string) error
- func (s *PostgresStore) PoolStats() PoolStats
- func (s *PostgresStore) RequeueTask(ctx context.Context, id string, reason string) error
- func (s *PostgresStore) ResetRunningContainers(ctx context.Context, id string) error
- func (s *PostgresStore) RetryTask(ctx context.Context, id string, maxRetries int) error
- func (s *PostgresStore) StartTask(ctx context.Context, id string, containerID string) error
- func (s *PostgresStore) UpdateInstanceDetails(ctx context.Context, id string, privateIP, az string) error
- func (s *PostgresStore) UpdateInstanceStatus(ctx context.Context, id string, status models.InstanceStatus) error
- func (s *PostgresStore) UpdateTaskStatus(ctx context.Context, id string, status models.TaskStatus, taskErr string) error
- func (s *PostgresStore) UpsertDiscordInstall(ctx context.Context, install *models.DiscordInstall) error
- func (s *PostgresStore) UpsertDiscordTaskThread(ctx context.Context, thread *models.DiscordTaskThread) error
- func (s *PostgresStore) UpsertReading(ctx context.Context, r *models.Reading) error
- func (s *PostgresStore) WithTx(ctx context.Context, fn func(Store) error) error
- type Store
- type TaskFilter
- type TaskResult
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a requested record does not exist.
Functions ¶
This section is empty.
Types ¶
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 (*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 (*PostgresStore) CreateAllowedSender ¶
func (s *PostgresStore) CreateAllowedSender(ctx context.Context, sender *models.AllowedSender) error
func (*PostgresStore) CreateInstance ¶
func (*PostgresStore) CreateTask ¶
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 (*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 (*PostgresStore) GetReadingByURL ¶
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) 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 (*PostgresStore) ResetRunningContainers ¶
func (s *PostgresStore) ResetRunningContainers(ctx context.Context, id string) error
func (*PostgresStore) RetryTask ¶
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) UpdateInstanceDetails ¶
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 ¶
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.