Documentation
¶
Overview ¶
Package pg keeps Lagrange's state in Postgres: the a2a-go task store, push config store, work queue and event queue that cluster mode needs, plus the tables the platform itself uses (users, addresses, tokens, task links, activity).
Postgres is the only dependency. The work queue uses FOR UPDATE SKIP LOCKED with leases, and LISTEN/NOTIFY wakes waiting workers and live views without polling.
Index ¶
- Constants
- func IsForeignKeyViolation(err error) bool
- func IsUniqueViolation(err error) bool
- func NewEventQueueManager(db *DB, poll time.Duration) eventqueue.Manager
- func NewWorkQueue(db *DB, workerID string, cfg WorkQueueConfig) workqueue.Queue
- type DB
- type PushStore
- func (s *PushStore) Delete(ctx context.Context, taskID a2a.TaskID, configID string) error
- func (s *PushStore) DeleteAll(ctx context.Context, taskID a2a.TaskID) error
- func (s *PushStore) Get(ctx context.Context, taskID a2a.TaskID, configID string) (*a2a.PushConfig, error)
- func (s *PushStore) List(ctx context.Context, taskID a2a.TaskID) ([]*a2a.PushConfig, error)
- func (s *PushStore) Save(ctx context.Context, taskID a2a.TaskID, config *a2a.PushConfig) (*a2a.PushConfig, error)
- type TaskStore
- func (s *TaskStore) Create(ctx context.Context, task *a2a.Task) (taskstore.TaskVersion, error)
- func (s *TaskStore) Get(ctx context.Context, taskID a2a.TaskID) (*taskstore.StoredTask, error)
- func (s *TaskStore) List(ctx context.Context, req *a2a.ListTasksRequest) (*a2a.ListTasksResponse, error)
- func (s *TaskStore) Load(ctx context.Context, taskID a2a.TaskID) (*taskstore.StoredTask, string, error)
- func (s *TaskStore) Update(ctx context.Context, req *taskstore.UpdateRequest) (taskstore.TaskVersion, error)
- type WorkQueue
- type WorkQueueConfig
Constants ¶
const ( // ChannelWork is notified when a work item is written. ChannelWork = "lagrange_work" // ChannelActivity is notified with the seq of each new activity row. ChannelActivity = "lagrange_activity" )
Notification channels.
Variables ¶
This section is empty.
Functions ¶
func IsForeignKeyViolation ¶
IsForeignKeyViolation reports whether err is a foreign key violation.
func IsUniqueViolation ¶
IsUniqueViolation reports whether err is a unique constraint violation.
func NewEventQueueManager ¶
func NewEventQueueManager(db *DB, poll time.Duration) eventqueue.Manager
NewEventQueueManager returns a2a-go's pull event queue reading the task_events table, so a subscriber on any replica follows a task executed on another one.
func NewWorkQueue ¶
func NewWorkQueue(db *DB, workerID string, cfg WorkQueueConfig) workqueue.Queue
NewWorkQueue returns an a2a-go work queue backed by db for cluster mode. workerID identifies this process in work_items.worker.
Types ¶
type DB ¶
DB is a connection pool plus a listener that fans out notifications.
type PushStore ¶
type PushStore struct {
// contains filtered or unexported fields
}
PushStore implements push.ConfigStore.
func NewPushStore ¶
NewPushStore returns a push config store backed by db.
func (*PushStore) Get ¶
func (s *PushStore) Get(ctx context.Context, taskID a2a.TaskID, configID string) (*a2a.PushConfig, error)
Get implements push.ConfigStore.
type TaskStore ¶
type TaskStore struct {
// contains filtered or unexported fields
}
TaskStore implements taskstore.Store. A task belongs to the tenant (the address) and the user (the sender) of the call that created it, both taken from the a2asrv CallContext. Calls from another user or tenant see a2a.ErrTaskNotFound, as the spec asks (3.3.2). Each change also appends an event for the pull event queue.
func NewTaskStore ¶
NewTaskStore returns a task store backed by db.
func (*TaskStore) List ¶
func (s *TaskStore) List(ctx context.Context, req *a2a.ListTasksRequest) (*a2a.ListTasksResponse, error)
List implements taskstore.Store. Like a2a-go's in-memory store it lists the caller's own tasks, newest first, and rejects anonymous callers.
func (*TaskStore) Load ¶
func (s *TaskStore) Load(ctx context.Context, taskID a2a.TaskID) (*taskstore.StoredTask, string, error)
Load returns a task and its tenant without checking who is asking. It is for the platform's own code (the inbox, the graph), never for A2A callers.
func (*TaskStore) Update ¶
func (s *TaskStore) Update(ctx context.Context, req *taskstore.UpdateRequest) (taskstore.TaskVersion, error)
Update implements taskstore.Store.
type WorkQueue ¶
type WorkQueue struct {
// contains filtered or unexported fields
}
WorkQueue is the workqueue.ReadWriter behind NewWorkQueue.
func NewWorkQueueBackend ¶
func NewWorkQueueBackend(db *DB, workerID string, cfg WorkQueueConfig) *WorkQueue
NewWorkQueueBackend returns the ReadWriter that NewWorkQueue wraps.
func (*WorkQueue) Close ¶
Close stops claiming work and cancels running executions, then waits up to wait for them to hand their items back. Items returned this way don't count as an attempt and are free for another worker at once; items that aren't returned in time are picked up when their lease expires.
func (*WorkQueue) Queue ¶
Queue returns the a2a-go queue that pulls from q. Executions run with a context that Close cancels.
type WorkQueueConfig ¶
type WorkQueueConfig struct {
// Lease is how long a claimed item stays with a worker without a heartbeat (default 10s).
Lease time.Duration
// MaxAttempts is how many times an item that fails is retried (default 3).
MaxAttempts int
// Poll is the longest a worker waits between claim attempts when no notification
// arrives (default 1s).
Poll time.Duration
}
WorkQueueConfig tunes the work queue. Zero values mean the defaults.