unit

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnitTypeTask   = "task"
	UnitTypeSignal = "signal"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Dependency

type Dependency struct {
	bun.BaseModel `bun:"table:blueprint_unit_dependencies"`

	UnitID      string `bun:"unit_id,pk"`
	DependsOnID string `bun:"depends_on_id,pk"`
}

Dependency is the bun model for blueprint_unit_dependencies.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

func New

func New(db *bun.DB) *Repository

func (*Repository) DecrementPendingDeps

func (r *Repository) DecrementPendingDeps(ctx context.Context, unitID string) error

DecrementPendingDeps decrements pending_deps for all direct successors of unitID. Must be called within a transaction — uses bunutil.IDB to pick up the tx from ctx.

func (*Repository) FindSignalUnit

func (r *Repository) FindSignalUnit(ctx context.Context, blueprintID, signalKey string) (ledger.Unit, error)

FindSignalUnit returns the signal unit for (blueprintID, signalKey) if it has not yet been completed. Returns sql.ErrNoRows if not found or already completed.

func (*Repository) Get

func (r *Repository) Get(ctx context.Context, unitID string) (ledger.Unit, error)

func (*Repository) Insert

func (r *Repository) Insert(ctx context.Context, units []*Unit) error

func (*Repository) InsertDependencies

func (r *Repository) InsertDependencies(ctx context.Context, deps []*Dependency) error

func (*Repository) SelectUnblocked

func (r *Repository) SelectUnblocked(ctx context.Context, unitID string) ([]ledger.Unit, error)

SelectUnblocked returns task units that became ready after unitID completed: pending_deps = 0, no prior dispatch or completion event, not signal units. FOR UPDATE prevents double-dispatch when two deps complete concurrently. Must be called within a transaction — uses bunutil.IDB to pick up the tx from ctx.

type Unit

type Unit struct {
	bun.BaseModel `bun:"table:blueprint_units"`

	ID          string    `bun:"id,pk,type:uuid"`
	BlueprintID string    `bun:"blueprint_id,notnull"`
	Key         string    `bun:"key,notnull"`
	UnitType    string    `bun:"unit_type,notnull,default:'task'"`
	PendingDeps int       `bun:"pending_deps,notnull"`
	CreatedAt   time.Time `bun:"created_at,notnull,default:now()"`
	UpdatedAt   time.Time `bun:"updated_at,notnull,default:now()"`
}

Unit is the bun model for blueprint_units.

Jump to

Keyboard shortcuts

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