thumbworker

package
v1.133.1 Latest Latest
Warning

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

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

Documentation

Overview

Package thumbworker draws every tile the platform shows. It claims the assets, resources and collections the stores say are owed one, renders each in the headless browser beside the platform, and records what it drew or why it could not (#1787).

A tile used to be drawn in whichever portal tab happened to be open, by a JavaScript reimplementation of CSS painting, and was wrong wherever that reimplementation fell short. Here the browser itself paints it, through the same renderers the viewer uses, and a document nobody opens still gets one.

Index

Constants

View Source
const DefaultRendererURL = "http://127.0.0.1:9222"

DefaultRendererURL is where the platform looks for its renderer when none is configured: a headless browser beside it in the same pod.

View Source
const Renderer = 2

Renderer is the generation of the renderer this worker draws as. A tile drawn by an older generation still serves and is drawn again; raising this redraws every tile in the library.

2 draws at twice the density and gives HTML and JSX a dark tile (#1789).

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetWork

type AssetWork interface {
	ClaimThumbnailWork(ctx context.Context, renderer int, lease time.Duration, limit int) ([]portaldomain.Asset, error)
	Update(ctx context.Context, id string, u portaldomain.AssetUpdate) error
	Get(ctx context.Context, id string) (*portaldomain.Asset, error)
}

AssetWork is what the worker asks of the asset store.

type Blobs

type Blobs interface {
	GetObject(ctx context.Context, bucket, key string) ([]byte, string, error)
	PutObject(ctx context.Context, bucket, key string, data []byte, contentType string) error
	DeleteObject(ctx context.Context, bucket, key string) error
}

Blobs is object storage.

type CollectionWork

type CollectionWork interface {
	ClaimCollectionThumbnailWork(ctx context.Context, lease time.Duration, limit int) ([]portaldomain.CollectionThumbnailWork, error)
	RecordCollectionThumbnail(ctx context.Context, id, key, source string) error
}

CollectionWork is what the worker asks of the collection store.

type Config

type Config struct {
	Enabled *bool `yaml:"enabled"`
	// RendererURL is the renderer's DevTools address, http:// or ws://.
	// Empty means DefaultRendererURL.
	RendererURL string `yaml:"renderer_url"`
}

Config is the deployment's `thumbnails:` section. A tile is drawn in a headless Chrome the platform reaches over the DevTools protocol, and the platform answers every request the browser makes itself, so the renderer needs no network of its own and never reaches back to the platform.

Enabled by default (nil = enabled). With no renderer answering, tiles keep their content-type icons and the platform logs once that it cannot draw.

func (Config) EffectiveRendererURL

func (c Config) EffectiveRendererURL() string

EffectiveRendererURL is RendererURL, or the default beside the platform.

func (Config) IsEnabled

func (c Config) IsEnabled() bool

IsEnabled reports whether the platform draws tiles, defaulting to true.

type Deps

type Deps struct {
	Drawer Drawer

	Assets      AssetWork
	Refs        RefLister
	AssetBlobs  Blobs
	Collections CollectionWork
	// CollectionBucket is where a collection's mosaic is stored.
	CollectionBucket string

	Resources      resource.ThumbnailWork
	ResourceBlobs  Blobs
	ResourceBucket string

	// Routes is the platform's own HTTP routes. The page a tile is drawn from
	// loads the viewer's chunks, the served slide runtime and a document's
	// declared references from the platform, and those requests are answered
	// by calling these routes in-process.
	Routes http.Handler
	// TileEntryURL and TileCSS are the tile page's script and stylesheet.
	TileEntryURL string
	TileCSS      string
}

Deps is what the worker draws with and where it records the result. Assets is required; collections and resources are drawn when their stores are present.

type Drawer

type Drawer interface {
	Ping(ctx context.Context) error
	Render(ctx context.Context, p headless.Page) ([]byte, error)
}

Drawer is the browser a tile is drawn in.

type RefLister

type RefLister interface {
	ListByAsset(ctx context.Context, assetID string) ([]assetrefs.Ref, error)
}

RefLister lists the references an asset declared.

type Tuning

type Tuning struct {
	// Poll is how long an idle worker waits before asking for work again.
	Poll time.Duration
	// Lease is how long a claimed row is held. It must outlast a render of
	// every variant; a replica that dies mid-render loses its lease at this.
	Lease time.Duration
	// Batch is how many rows of each kind one pass claims.
	Batch int
	// RenderTimeout bounds one render. A document that has not reported itself
	// drawn by then is recorded as not drawable.
	RenderTimeout time.Duration
}

Tuning paces the worker. The zero value is the defaults.

type Worker

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

Worker draws owed tiles until stopped.

func New

func New(cfg Tuning, deps Deps) *Worker

New returns a worker. It does nothing until Start.

func (*Worker) Start

func (w *Worker) Start(ctx context.Context)

Start runs the worker until ctx ends or Stop is called. A nil worker, which is what a deployment with nothing to draw has, does nothing.

func (*Worker) Stop

func (w *Worker) Stop()

Stop ends the worker and waits for the render in progress, if any.

Jump to

Keyboard shortcuts

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