checkpoints

package
v0.0.0-...-ddbf6aa Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package checkpoints contains methods for maintaining and using process checkpoints to ensure processes run once only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists(ctx context.Context, key Key) (bool, error)

Exists returns whether a checkpoint with the given key eixsts.

func Insert

func Insert(ctx context.Context, key Key, ttl time.Duration) *spanner.Mutation

Insert inserts a checkpoint with the given key and TTL.

func SetForTesting

func SetForTesting(ctx context.Context, t testing.TB, cs ...Checkpoint) error

SetForTesting replaces the set of stored checkpoints to match the given set.

func SortKeys

func SortKeys(cs []Key)

SortKeys sorts keys in place in ascending order by Project, ResourceId, ProcessId, Uniquifier.

Types

type Checkpoint

type Checkpoint struct {
	Key
	// The time the checkpoint was created.
	CreationTime time.Time
	// The time the checkpoint will be eligible for deletion.
	ExpiryTime time.Time
}

Checkpoint records that a point in a process was reached.

func ReadAllForTesting

func ReadAllForTesting(ctx context.Context) ([]Checkpoint, error)

ReadAllForTesting reads all checkpoints for testing, e.g. to assert all expected checkpoints were made. Do not use in production, will not scale. Must be called in a spanner transactional context.

type Key

type Key struct {
	// Project is the name of the LUCI Project.
	Project string
	// Identifier of the resource to which the checkpoint relates.
	// For example, the ResultDB invocation being ingested.
	// Free-form field, but must be non-empty.
	ResourceID string
	// ProcessID is the identifier of the process requiring checkpointing.
	// Valid pattern: ^[a-z0-9\-/]{1,64}$.
	ProcessID string
	// Unique identifier of the checkpoint within the process and resource.
	// Free-form field.
	// If the process has only one checkpoint, this may be empty ("").
	Uniquifier string
}

Key is the primary key of a checkpoint.

Jump to

Keyboard shortcuts

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