task_cfg_cache

package
v0.0.0-...-d3367c0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// We use a single BigTable table for storing gob-encoded TaskSpecs and
	// JobSpecs.
	BT_TABLE = "tasks-cfg"

	// We use a single BigTable column family.
	BT_COLUMN_FAMILY = "CFGS"

	// We use a single BigTable column which stores gob-encoded TaskSpecs
	// and JobSpecs.
	BT_COLUMN = "CFG"

	INSERT_TIMEOUT = 30 * time.Second
	QUERY_TIMEOUT  = 5 * time.Second
)

Variables

View Source
var (
	// Fully-qualified BigTable column name.
	BT_COLUMN_FULL = fmt.Sprintf("%s:%s", BT_COLUMN_FAMILY, BT_COLUMN)

	ErrNoSuchEntry = atomic_miss_cache.ErrNoSuchEntry
)

Functions

func GetTaskSpec

func GetTaskSpec(ctx context.Context, c TaskCfgCache, rs types.RepoState, name string) (*specs.TaskSpec, error)

GetTaskSpec returns the TaskSpec at the given RepoState, or an error if no such TaskSpec exists.

func MakeJob

func MakeJob(ctx context.Context, c TaskCfgCache, rs types.RepoState, name string) (*types.Job, error)

MakeJob is a helper function which retrieves the given JobSpec at the given RepoState and uses it to create a Job instance.

func WriteTasksCfgToBigTable

func WriteTasksCfgToBigTable(ctx context.Context, table *bigtable.Table, key string, cv *CachedValue) error

WriteTasksCfgToBigTable writes the given CachedValue to BigTable.

Types

type CachedValue

type CachedValue struct {
	// RepoState is the RepoState which is associated with this TasksCfg.
	RepoState types.RepoState
	// Cfg is the TasksCfg for this entry.
	Cfg *specs.TasksCfg
	// Err stores a permanent error. Mutually-exclusive with Cfg.
	Err string
}

CachedValue represents a cached TasksCfg value. It includes any permanent error, which cannot be recovered via retries.

func GetTasksCfgFromBigTable

func GetTasksCfgFromBigTable(ctx context.Context, table *bigtable.Table, rowKey string) (*CachedValue, error)

GetTasksCfgFromBigTable retrieves a CachedValue from BigTable.

type TaskCfgCache

type TaskCfgCache interface {
	// Cleanup removes cache entries which are outside of our scheduling window.
	Cleanup(ctx context.Context, period time.Duration) error

	// Close frees up resources used by the TaskCfgCache.
	Close() error

	// Get returns the TasksCfg (or error) for the given RepoState in the cache.
	// If the given entry does not exist in the cache, reads through to the
	// backing store to find it there and adds to the cache if it exists. If no
	// entry exists for the given RepoState, returns ErrNoSuchEntry. If there is
	// a cached (ie. permanent non-recoverable) error for this RepoState, it is
	// returned as the second return value.
	Get(context.Context, types.RepoState) (*specs.TasksCfg, error, error)

	// Sets the TasksCfg (or error) for the given RepoState in the cache.
	Set(ctx context.Context, rs types.RepoState, cfg *specs.TasksCfg, storedErr error) error

	// Sets the TasksCfg (or error) for the given RepoState in the cache by
	// calling the given function if no value already exists. Returns the
	// existing or new CachedValue, or any error which occurred.
	SetIfUnset(ctx context.Context, rs types.RepoState, fn func(context.Context) (*CachedValue, error)) (*CachedValue, error)
}

type TaskCfgCacheImpl

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

TaskCfgCacheImpl is a struct used for caching tasks cfg files. The user should periodically call Cleanup() to remove old entries.

func NewTaskCfgCache

func NewTaskCfgCache(ctx context.Context, repos repograph.Map, btProject, btInstance string, ts oauth2.TokenSource) (*TaskCfgCacheImpl, error)

NewTaskCfgCache returns a TaskCfgCache instance.

func (*TaskCfgCacheImpl) Cleanup

func (c *TaskCfgCacheImpl) Cleanup(ctx context.Context, period time.Duration) error

Cleanup removes cache entries which are outside of our scheduling window.

func (*TaskCfgCacheImpl) Close

func (c *TaskCfgCacheImpl) Close() error

Close implements TaskCfgCache.

func (*TaskCfgCacheImpl) Get

Get implements TaskCfgCache.

func (*TaskCfgCacheImpl) Set

func (c *TaskCfgCacheImpl) Set(ctx context.Context, rs types.RepoState, cfg *specs.TasksCfg, storedErr error) error

Sets the TasksCfg (or error) for the given RepoState in the cache.

func (*TaskCfgCacheImpl) SetIfUnset

func (c *TaskCfgCacheImpl) SetIfUnset(ctx context.Context, rs types.RepoState, fn func(context.Context) (*CachedValue, error)) (*CachedValue, error)

Sets the TasksCfg (or error) for the given RepoState in the cache by calling the given function if no value already exists. Returns the existing or new CachedValue, or any error which occurred.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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