jobs

package
v0.0.0-...-25a572b Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package jobs supports jobs, which are collections of enqueued tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

func NewDB

func NewDB(ctx context.Context, projectID, namespace string) (_ *DB, err error)

NewDB creates a new database client for jobs.

func (*DB) CreateJob

func (d *DB) CreateJob(ctx context.Context, j *Job) (err error)

CreateJob creates a new job. It returns an error if a job with the same ID already exists.

func (*DB) DeleteJob

func (d *DB) DeleteJob(ctx context.Context, id string) (err error)

DeleteJob deletes the job with the given ID. It does not return an error if the job doesn't exist.

func (*DB) GetJob

func (d *DB) GetJob(ctx context.Context, id string) (_ *Job, err error)

GetJob retrieves the job with the given ID. It returns an error if the job does not exist.

func (*DB) Increment

func (d *DB) Increment(ctx context.Context, id, name string, n int) (err error)

Increment value named name by n.

func (*DB) ListJobs

func (d *DB) ListJobs(ctx context.Context, f func(_ *Job, lastUpdate time.Time) error) (err error)

ListJobs calls f on each job in the DB, most recently started first. f is also passed the time that the job was last updated. If f returns a non-nil error, the iteration stops and returns that error.

func (*DB) UpdateJob

func (d *DB) UpdateJob(ctx context.Context, id string, f func(*Job) error) (err error)

UpdateJob gets the job with the given ID, which must exist, then calls f on it, then writes it back to the database. These actions occur atomically. If f returns an error, that error is returned and no update occurs.

type Job

type Job struct {
	User          string
	StartedAt     time.Time
	URL           string // The URL that initiated the job.
	Binary        string // Name of binary.
	BinaryVersion string // Hex-encoded hash of binary.
	BinaryArgs    string // The args to the binary.
	Canceled      bool   // The job was canceled.
	// Counts of tasks.
	NumEnqueued  int // Written by enqueue endpoint.
	NumStarted   int // Incremented at the start of a scan.
	NumSkipped   int // Previously run, stored in BigQuery.
	NumFailed    int // The HTTP request failed (status != 200)
	NumErrored   int // The HTTP request succeeded, but the scan resulted in an error.
	NumSucceeded int
}

A Job is a set of related scan tasks enqueued at the same time.

func NewJob

func NewJob(user string, start time.Time, url, binaryName, binaryVersion, binaryArgs string) *Job

NewJob creates a new Job.

func (*Job) ID

func (j *Job) ID() string

ID returns a unique identifier for a job which can serve as a database key.

func (*Job) NumFinished

func (j *Job) NumFinished() int

Jump to

Keyboard shortcuts

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