platform

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func StateOf

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

func (c Crossings) Admitted(ctx context.Context, quota string) error

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

func (c Crossings) On() bool

On reports whether anybody listens: a caller may skip what it would read only to tell.

func (Crossings) Refused

func (c Crossings) Refused(ctx context.Context, workspace shared.ID, quota string, limit int64)

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

func (c Crossings) Spent(ctx context.Context, budget string, day, at time.Time)

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) On

func (r Recorder) On() bool

On reports whether events are written at all.

func (Recorder) OwnersChanged

func (r Recorder) OwnersChanged(ctx context.Context, actor event.Actor, at time.Time) error

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.

Jump to

Keyboard shortcuts

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