scripttiles

package
v1.137.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package scripttiles keeps the tile each managed script is shown by in the scripts listing's grid view (#1909): its flow diagram (#1906), drawn by the tile worker (internal/platform/thumbworker) in the same headless browser every other tile is drawn in, light and dark.

A tile is keyed by the script and names the version it was drawn from, so saving a version owes a new one whatever the version changed. A version that does not parse is recorded as not drawable, with the parse error as the reason, and draws when a later version parses. Claiming, holding back and giving up follow the rules the worker applies to every other tile.

Index

Constants

View Source
const (
	VariantLight = "light"
	VariantDark  = "dark"
)

Variants of a tile.

Variables

View Source
var ErrNoTile = errors.New("this script has no tile")

ErrNoTile is a script with no tile to serve: never drawn, or its current version is recorded as not drawable.

Functions

func DarkKey

func DarkKey(lightKey string) string

DarkKey is the dark tile stored beside the light one at lightKey.

func Key

func Key(prefix, scriptID, variant string) string

Key is where a script's tile variant is stored: under the portal's prefix, one pair per script, redrawn in place.

Types

type ObjectGetter

type ObjectGetter interface {
	GetObject(ctx context.Context, bucket, key string) ([]byte, string, error)
}

ObjectGetter reads one stored object.

type Orphan

type Orphan struct {
	ScriptID string
	Key      string
}

Orphan is the stored tile of a script that no longer exists.

type Reader

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

Reader serves a script's stored tile.

func NewReader

func NewReader(store *Store, blobs ObjectGetter, bucket string) *Reader

NewReader builds a reader over the store and the bucket tiles are stored in.

func (*Reader) Tile

func (r *Reader) Tile(ctx context.Context, scriptID, variant string) (data []byte, current bool, err error)

Tile is one variant of a script's tile, or ErrNoTile, and whether it was drawn from the version the script is at (see CurrentKey).

type Store

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

Store is the Postgres record of every script's tile.

func NewPostgres

func NewPostgres(db *sql.DB) *Store

NewPostgres builds the store over db.

func (*Store) Claim

func (s *Store) Claim(ctx context.Context, renderer int, lease time.Duration, limit int) ([]Work, error)

Claim leases up to limit scripts owed a tile for lease, drawn by renderer generation renderer.

func (*Store) CurrentKey

func (s *Store) CurrentKey(ctx context.Context, scriptID string) (key string, current bool, err error)

CurrentKey is the stored light tile of a script, unless its current version is recorded as not drawable: that script is shown by the placeholder, not by an older version's diagram. current is false while the stored tile is an older version's, the one a script shows until the worker draws the version it is at. The id is compared as text, so an id that is not a script's is no tile rather than a malformed query.

func (*Store) Forget

func (s *Store) Forget(ctx context.Context, scriptID string) error

Forget removes a deleted script's tile row, once its objects are gone.

func (*Store) Hold

func (s *Store) Hold(ctx context.Context, scriptID string, hold time.Duration, attempts int) error

Hold holds a script back from the next claim for hold after an attempt that did not finish.

func (*Store) Orphans

func (s *Store) Orphans(ctx context.Context, limit int) ([]Orphan, error)

Orphans lists up to limit tile rows whose script was deleted.

func (*Store) Record

func (s *Store) Record(ctx context.Context, scriptID string, version int, key string, renderer int) error

Record stores that version's tile at key, drawn by renderer.

func (*Store) RecordFailure

func (s *Store) RecordFailure(ctx context.Context, scriptID string, version int, reason string) error

RecordFailure stores that version cannot be drawn, and why. It is not claimed again until a later version is saved.

type Work

type Work struct {
	ScriptID string
	Name     string
	Version  int
	Source   string
	// Key is the tile stored now, empty when there is none.
	Key      string
	Attempts int
}

Work is one script owed a tile.

Jump to

Keyboard shortcuts

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