Documentation
¶
Overview ¶
Package app is the application layer of the quickstart service: its commands, its queries, the task_list Projection and the notify_assignee Reactor. The same App runs in memory and on Postgres; only the Store, UnitOfWork, Runtime and ReadModel passed to New differ.
Index ¶
- Constants
- Variables
- func Codec() *eventstore.Codec
- func FormatPosition(c eventstore.Cursor) string
- func Metadata(tenant string, next http.Handler) http.Handler
- func NotifyAssignee(codec *eventstore.Codec, tasks *Tasks, mailer Mailer) *consumer.Router
- func ParsePosition(s string) (eventstore.Cursor, error)
- func ReceiveTrackerWebhook(store *inbox.Store) http.Handler
- func TaskListV1(codec *eventstore.Codec, rm ReadModel) *consumer.Router
- type App
- func (a *App) CompleteTask(ctx context.Context, id todo.TaskID) (eventstore.CommandResult, error)
- func (a *App) Consumers() consumer.Group
- func (a *App) HandleTrackerWebhook(ctx context.Context, d inbox.Delivery) error
- func (a *App) ListTasks(ctx context.Context, after eventstore.Cursor) ([]Task, consumer.Freshness, error)
- func (a *App) OpenTask(ctx context.Context, in OpenTask) (todo.TaskID, eventstore.CommandResult, error)
- func (a *App) Routes(mux *http.ServeMux)
- type Config
- type InMemoryReadModel
- func (m *InMemoryReadModel) Clear(ctx context.Context) error
- func (m *InMemoryReadModel) Insert(ctx context.Context, tenant string, task Task) error
- func (m *InMemoryReadModel) List(_ context.Context, tenant string) ([]Task, error)
- func (m *InMemoryReadModel) SetDone(ctx context.Context, tenant string, id uuid.UUID) error
- func (m *InMemoryReadModel) SetNotified(ctx context.Context, tenant string, id uuid.UUID) error
- type Mail
- type Mailer
- type OpenTask
- type PgReadModel
- func (m *PgReadModel) Clear(ctx context.Context) error
- func (m *PgReadModel) Insert(ctx context.Context, tenant string, task Task) error
- func (m *PgReadModel) List(ctx context.Context, tenant string) ([]Task, error)
- func (m *PgReadModel) SetDone(ctx context.Context, tenant string, id uuid.UUID) error
- func (m *PgReadModel) SetNotified(ctx context.Context, tenant string, id uuid.UUID) error
- type ReadModel
- type Task
- type Tasks
- type TrackerWebhook
Constants ¶
const TrackerSource = "tracker"
TrackerSource is the Inbox Source of the issue tracker's webhooks.
Variables ¶
var ErrInvalidAddress = errors.New("app: invalid mail address")
ErrInvalidAddress is returned by a Mailer for an address it can never deliver to.
Functions ¶
func Codec ¶
func Codec() *eventstore.Codec
Codec registers the service's events. Every service owns its Codec.
func FormatPosition ¶
func FormatPosition(c eventstore.Cursor) string
FormatPosition encodes a CommandResult.Position for an API client.
func Metadata ¶
Metadata puts the request metadata into the request ctx: the fixed Tenant of a single-tenant service, the Actor and the request ID, which becomes the Correlation of the events the request writes (ADR-0010).
The X-User header stands in for real authentication. With pkg/connectrpc's jwtauth interceptor, Claims.UserID is the Actor and Claims.TenantID the Tenant without any of this.
func NotifyAssignee ¶
NotifyAssignee builds the handler of the notify_assignee Reactor: it mails the assignee of an opened Task, then records that with a follow-up command. Delivery is at least once, so the mail carries the event ID as its idempotency key and MarkNotified is idempotent.
func ParsePosition ¶
func ParsePosition(s string) (eventstore.Cursor, error)
ParsePosition decodes a position from FormatPosition. The empty string is the zero Cursor.
func ReceiveTrackerWebhook ¶
ReceiveTrackerWebhook stores a tracker webhook in the Inbox and answers 202 at once; the Worker of TrackerSource handles it. A redelivered webhook is deduplicated by its delivery ID.
func TaskListV1 ¶
func TaskListV1(codec *eventstore.Codec, rm ReadModel) *consumer.Router
TaskListV1 builds version 1 of the task_list Projection. Every write notifies subscribers, so a live UI can refetch the task.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App runs the service's commands and queries.
func (*App) CompleteTask ¶
func (a *App) CompleteTask(ctx context.Context, id todo.TaskID) (eventstore.CommandResult, error)
CompleteTask marks a Task as done.
func (*App) HandleTrackerWebhook ¶
HandleTrackerWebhook is the inbox.Handler of TrackerSource: it completes the Task the webhook names.
func (*App) ListTasks ¶
func (a *App) ListTasks(ctx context.Context, after eventstore.Cursor) ([]Task, consumer.Freshness, error)
ListTasks returns the Tenant's tasks once the task_list Projection has caught up to after, the Position of the caller's last command. When it has not caught up within the budget, the tasks are returned anyway, marked Stale.
type Config ¶
type Config struct {
Codec *eventstore.Codec
Store eventstore.Store
UnitOfWork eventstore.UnitOfWork
Runtime consumer.Runtime
ReadModel ReadModel
Mailer Mailer
}
Config wires an App to one backend.
type InMemoryReadModel ¶
type InMemoryReadModel struct {
// contains filtered or unexported fields
}
InMemoryReadModel keeps the task_list read model in memory. Its writes go through postgres.Stage, so they commit or roll back with the Cursor transaction of an InMemoryRuntime.
func NewInMemoryReadModel ¶
func NewInMemoryReadModel() *InMemoryReadModel
NewInMemoryReadModel returns an empty InMemoryReadModel.
func (*InMemoryReadModel) Clear ¶
func (m *InMemoryReadModel) Clear(ctx context.Context) error
Clear removes every task.
func (*InMemoryReadModel) SetNotified ¶
SetNotified marks the task id as notified.
type Mail ¶
type Mail struct {
To string
Subject string
// IdempotencyKey lets the mail provider drop a repeated send.
IdempotencyKey string
}
Mail is one outbound mail.
type PgReadModel ¶
type PgReadModel struct {
// contains filtered or unexported fields
}
PgReadModel keeps the task_list read model in the task_list_v1 table and reads it through the task_list view (migrations/000002_task_list.up.sql). Its writes join the Cursor transaction through postgres.Conn.
func NewPgReadModel ¶
func NewPgReadModel(pool *pgxpool.Pool) *PgReadModel
NewPgReadModel returns a PgReadModel on pool.
func (*PgReadModel) Clear ¶
func (m *PgReadModel) Clear(ctx context.Context) error
Clear removes every task.
func (*PgReadModel) SetNotified ¶
SetNotified marks the task id as notified.
type ReadModel ¶
type ReadModel interface {
Insert(ctx context.Context, tenant string, task Task) error
SetDone(ctx context.Context, tenant string, id uuid.UUID) error
SetNotified(ctx context.Context, tenant string, id uuid.UUID) error
List(ctx context.Context, tenant string) ([]Task, error)
// Clear empties the read model; only projection.Reset needs it.
Clear(ctx context.Context) error
}
ReadModel stores the task_list read model. Its writes run in the Cursor transaction in ctx, so they commit together with the Projection's Cursor.
type Task ¶
type Task struct {
ID uuid.UUID `json:"id"`
Title string `json:"title"`
Assignee string `json:"assignee"`
Done bool `json:"done"`
Notified bool `json:"notified"`
OpenedAt time.Time `json:"opened_at"`
}
Task is one row of the task_list read model.
type Tasks ¶
type Tasks = eventstore.Repository[todo.TaskID, todo.Task, *todo.Task]
Tasks is the Repository of Task Aggregates.
type TrackerWebhook ¶
type TrackerWebhook struct {
DeliveryID string `json:"delivery_id"`
TaskID uuid.UUID `json:"task_id"`
}
TrackerWebhook is the body of a tracker webhook: a task was closed in the tracker.