cache

package
v0.0.0-...-4fe5f23 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: BSD-3-Clause Imports: 10 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JobCache

type JobCache interface {
	// GetAllCachedJobs returns every job in the cache.
	GetAllCachedJobs() []*types.Job

	// GetJob returns the job with the given ID, or an error if no such job exists.
	GetJob(string) (*types.Job, error)

	// GetJobMaybeExpired does the same as GetJob but tries to dig into the
	// DB in case the Job is old enough to have scrolled out of the cache
	// window.
	GetJobMaybeExpired(context.Context, string) (*types.Job, error)

	// GetJobsByRepoState retrieves all known jobs with the given name at
	// the given RepoState. Does not search the underlying DB.
	GetJobsByRepoState(string, types.RepoState) ([]*types.Job, error)

	// GetJobsFromDateRange retrieves all jobs which were created in the
	// given date range.
	GetJobsFromDateRange(time.Time, time.Time) ([]*types.Job, error)

	// GetMatchingJobsFromDateRange retrieves all jobs which were created
	// in the given date range and match one of the given job names.
	GetMatchingJobsFromDateRange(names []string, from time.Time, to time.Time) (map[string][]*types.Job, error)

	// RequestedJobs returns a list of jobs which were not yet started at
	// the time of the last cache update.
	RequestedJobs() ([]*types.Job, error)

	// InProgressJobs returns a list of jobs which were started but not finished
	// at the time of the last cache update.
	InProgressJobs() ([]*types.Job, error)

	// Update loads new jobs from the database.
	Update(ctx context.Context) error

	// AddJobs adds jobs directly to the JobCache.
	AddJobs([]*types.Job)

	// LastUpdated is the timestamp of the last call to Update.
	LastUpdated() time.Time
}

func NewJobCache

func NewJobCache(ctx context.Context, d db.JobReader, timeWindow window.Window, onModifiedJobs func()) (JobCache, error)

NewJobCache returns a local cache which provides more convenient views of job data than the database can provide. The last parameter is a callback function which is called when modified tasks are received from the DB. This is used for testing.

type TaskCache

type TaskCache interface {

	// GetTask returns the task with the given ID, or an error if no such task exists.
	GetTask(id string) (*types.Task, error)

	// GetTaskMaybeExpired does the same as GetTask but tries to dig into
	// the DB in case the Task is old enough to have scrolled out of the
	// cache window.
	GetTaskMaybeExpired(context.Context, string) (*types.Task, error)

	// GetTaskForCommit retrieves the task with the given name whose blamelist
	// includes the given commit, or nil if no such task exists.
	GetTaskForCommit(repo string, revision string, name string) (*types.Task, error)

	// GetTasksByKey returns the tasks with the given TaskKey, sorted
	// by creation time.
	GetTasksByKey(key types.TaskKey) ([]*types.Task, error)

	// GetTasksForCommits retrieves all tasks which included[1] each of the
	// given commits. Returns a map whose keys are commit hashes and values are
	// sub-maps whose keys are task spec names and values are tasks.
	//
	// 1) Blamelist calculation is outside the scope of the taskCache, but the
	//    implied assumption here is that there is at most one task for each
	//    task spec which has a given commit in its blamelist. The user is
	//    responsible for inserting tasks into the database so that this invariant
	//    is maintained. Generally, a more recent task will "steal" commits from an
	//    earlier task's blamelist, if the blamelists overlap. There are three
	//    cases to consider:
	//       1. The newer task ran at a newer commit than the older task. Its
	//          blamelist consists of all commits not covered by the previous task,
	//          and therefore does not overlap with the older task's blamelist.
	//       2. The newer task ran at the same commit as the older task. Its
	//          blamelist is the same as the previous task's blamelist, and
	//          therefore it "steals" all commits from the previous task, whose
	//          blamelist becomes empty.
	//       3. The newer task ran at a commit which was in the previous task's
	//          blamelist. Its blamelist consists of the commits in the previous
	//          task's blamelist which it also covered. Those commits move out of
	//          the previous task's blamelist and into the newer task's blamelist.
	GetTasksForCommits(repo string, commits []string) (map[string]map[string]*types.Task, error)

	// GetTasksFromDateRange retrieves all tasks which were created in the given
	// date range.
	GetTasksFromDateRange(from time.Time, to time.Time) ([]*types.Task, error)

	// KnownTaskName returns true iff the given task name has been seen
	// before for a non-forced, non-tryjob run.
	KnownTaskName(repo string, name string) bool

	// UnfinishedTasks returns a list of tasks which were not finished at
	// the time of the last cache update. Fake tasks are not included.
	UnfinishedTasks() ([]*types.Task, error)

	// Update loads new tasks from the database.
	Update(ctx context.Context) error

	// AddTasks adds tasks directly to the TaskCache.
	AddTasks(tasks []*types.Task)
}

func NewTaskCache

func NewTaskCache(ctx context.Context, d db.TaskReader, timeWindow window.Window, onModifiedTasks func()) (TaskCache, error)

NewTaskCache returns a local cache which provides more convenient views of task data than the database can provide. The last parameter is a callback function which is called when modified tasks are received from the DB. This is used for testing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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