db

package
v0.0.0-...-ed2b81c Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusPending   = "pending"
	StatusRunning   = "running"
	StatusSucceeded = "succeeded"
	StatusFailed    = "failed"
)

Variables

View Source
var (
	ErrNoOutstandingJobs = errors.New("no pending jobs")
	ErrJobNotFound       = errors.New("job not found")
)

Functions

This section is empty.

Types

type DB

type DB interface {
	// EnqueueJob enqueues a query to be run in a specific repository at a
	// specific point in the commit history.
	//
	// Input QueryJob must have the Repository, CommitHash, Query fields
	// populated.
	//
	// On exit, QueryJob has the ID and QueueTime fields populated.
	//
	// If there is an existing non-failed job with the same Repository, CommitHash, and
	// Query, enqueue requests should deduplicate to the same request ID; failed
	// jobs are ignored for the purposes of this deduplication.
	EnqueueJob(context.Context, *QueryJob) error

	DequeueJob(ctx context.Context, workerName string) (*QueryJob, error)

	GetJob(ctx context.Context, id string) (*QueryJob, error)

	FinishJob(ctx context.Context, id string, status string, result string) error

	io.Closer
}

The invariants of the DB are:

  • There should be only one (repository, commit, query) tuple in the non-failed state (either queued or running or succeeded) at any point in time
  • There can be multiple (repository, commit, query) tuples in the failed state

type Fake

type Fake struct {
	Queue []FakeQueueEntry

	EnqueueJobErr error
	GetJobErr     error
	FinishJobErr  error
}

func (*Fake) Close

func (f *Fake) Close() error

func (*Fake) DequeueJob

func (f *Fake) DequeueJob(ctx context.Context, workerName string) (*QueryJob, error)

func (*Fake) EnqueueJob

func (f *Fake) EnqueueJob(ctx context.Context, job *QueryJob) error

func (*Fake) FinishJob

func (f *Fake) FinishJob(ctx context.Context, id string, status string, result string) error

func (*Fake) GetJob

func (f *Fake) GetJob(ctx context.Context, id string) (*QueryJob, error)

type FakeQueueEntry

type FakeQueueEntry struct {
	Job *QueryJob
	Err error
}

type QueryJob

type QueryJob struct {
	Repository  string     `datastore:"repository"`
	CommitHash  string     `datastore:"commit_hash"`
	Query       string     `datastore:"query_string"`
	ID          string     `datastore:"id"`
	Status      string     `datastore:"status"`
	Worker      *string    `datastore:"worker"`
	QueueTime   time.Time  `datastore:"queue_time"`
	StartTime   *time.Time `datastore:"start_time"`
	FinishTime  *time.Time `datastore:"finish_time"`
	ResultURL   *string    `datastore:"result_url"`
	ResultError *string    `datastore:"result_error"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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