Documentation
¶
Overview ¶
Package platform writes the installation's events: what a provider's purchase platform learns about a workspace (UC-INS-14, multi-tenancy.md §4.3). Every place that changes what such an event reports calls the one Recorder, inside the change's own transaction, so an event is written exactly when its change commits and carries the state the change left.
Index ¶
- func StateOf(record adminrepo.TenantRecord) event.WorkspaceState
- type Crossings
- type Recorder
- func (r Recorder) On() bool
- func (r Recorder) OwnersChanged(ctx context.Context, actor event.Actor, at time.Time) error
- func (r Recorder) Record(ctx context.Context, eventType event.Type, actor event.Actor, at time.Time, ...) error
- func (r Recorder) RecordDeleted(ctx context.Context, last adminrepo.TenantRecord, actor event.Actor, ...) error
- func (r Recorder) RecordOnce(ctx context.Context, eventType event.Type, actor event.Actor, at time.Time, ...) (bool, error)
- type Workspaces
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StateOf ¶
func StateOf(record adminrepo.TenantRecord) event.WorkspaceState
StateOf is what an event reports of a workspace's row.
Types ¶
type Crossings ¶
type Crossings struct {
Marks quotarepo.Reached
Recorder Recorder
UnitOfWork persistence.UnitOfWork
// Scopes names the workspace a metering's transaction runs for, which the budget's event is
// written for once that transaction has ended.
Scopes persistence.ScopeSource
Clock clock.Clock
}
Crossings tells a purchase platform that a workspace reached one of its limits or spent its AI budget, once per crossing rather than once per refused request (UC-INS-14 check 2). The quota guard calls it; the mark that makes it once is the workspace's `quota_reached` row.
func (Crossings) Admitted ¶
Admitted is told a create of the quota was let through: the workspace is below the limit again, so the next refusal is the next crossing. In the create's own transaction.
func (Crossings) On ¶
On reports whether anybody listens: a caller may skip what it would read only to tell.
func (Crossings) Refused ¶
Refused is told a create of the quota was refused at `limit`. The refused transaction rolls back with the refusal, so the mark and the event are written once it has ended, in a transaction of their own (persistence.After); only the call that sets the mark writes the event.
func (Crossings) Spent ¶
Spent is told the workspace's day of `budget` has been spent by the metering in progress. The mark and the event are written once the metering's transaction has ended, in one of their own: an answered AI call stays metered whatever becomes of telling it, and the day's mark makes it once, also when two meterings cross it at once.
type Recorder ¶
type Recorder struct {
Events adminrepo.PlatformEvents
Workspaces Workspaces
IDs clock.IDGenerator
Tenancy env.TenancyMode
}
Recorder writes installation events. The zero value writes nothing, which is what a build or a test without the feed gets; single mode writes nothing either, since nothing there could read them (UC-INS-14 check 7).
func (Recorder) OwnersChanged ¶
OwnersChanged writes `owner_changed` about the transaction's workspace: who the owners are is the workspace's, and the event names none of them.
func (Recorder) Record ¶
func (r Recorder) Record(ctx context.Context, eventType event.Type, actor event.Actor, at time.Time, extra map[string]any, ) error
Record writes one event about the transaction's workspace, with the state it reads there - the state the change in progress has left. `extra` holds the event's own fields.
func (Recorder) RecordDeleted ¶
func (r Recorder) RecordDeleted(ctx context.Context, last adminrepo.TenantRecord, actor event.Actor, at time.Time, ) error
RecordDeleted writes the last event about a workspace its purge is removing, and removes the platform's reference from the workspace's kept events: the reference leaves with the workspace (multi-tenancy.md §4.3). The state is the last one read with the version one higher, so a receiver keeping the newest keeps this one.
func (Recorder) RecordOnce ¶
func (r Recorder) RecordOnce(ctx context.Context, eventType event.Type, actor event.Actor, at time.Time, extra map[string]any, key string, ) (bool, error)
RecordOnce is Record for a writer that may run twice: the event is written once per key, and the answer says whether this call wrote it.
type Workspaces ¶
type Workspaces interface {
Find(ctx context.Context) (adminrepo.TenantRecord, error)
}
Workspaces reads the transaction's own workspace, as the control plane does.