jobs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: CC0-1.0 Imports: 8 Imported by: 0

Documentation

Overview

Package jobs keeps track of work to be done against the database, including queuing.

It provides a Repository interface for generalized interactions storing and retrieving jobs from a data store, as well as a concrete type that implements that interface for a PostgreSQL database using the pgx package.

Index

Constants

This section is empty.

Variables

View Source
var ErrAllQueued = errors.New("All items have been queued for this destination")

ErrAllQueued is returned when there is need to enqueue any more items for a destination. This would be an expected error.

View Source
var ErrNoJobs = errors.New("There are no ready jobs for that destination")

ErrNoJobs is returned when there are no ready jobs for a particular destination. This would be an expected error.

Functions

This section is empty.

Types

type FullText

type FullText struct {
	ID          uuid.UUID
	ItemID      string
	Destination string
	Started     sql.NullTime
	Finished    sql.NullTime
	Status      string
}

FullText is a record of how jobs with the full text of items were passed on to some particular destination. It can handle recording full text jobs at either the item (i.e., resource) or file level, and it can handle multiple destinations.

func NewFullText

func NewFullText(itemID string, destination string) *FullText

NewFullText creates a new, unstarted job for full text. You must specify which item this is associated with, what the destination is (i.e., the job to be done), and whether or not it has full text associated with it. (If it does not have full text, presumably you will skip the job.)

func (*FullText) Fail

func (job *FullText) Fail()

Fail adds the current time to the finished field and changes the job status.

func (*FullText) Finish

func (job *FullText) Finish()

Finish adds the current time to the finished field and changes the job status.

func (*FullText) Skip

func (job *FullText) Skip()

Skip adds the current time to the finished field and changes the job status.

func (*FullText) Start

func (job *FullText) Start()

Start adds the current time to the started field and changes the job status.

func (FullText) String

func (job FullText) String() string

type Repo

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

Repo is a data store using PostgreSQL with the pgx native interface.

func NewJobsRepo

func NewJobsRepo(db *pgxpool.Pool) *Repo

NewJobsRepo returns an item repo using PostgreSQL with the pgx native interface.

func (*Repo) CreateJobForUnqueued

func (r *Repo) CreateJobForUnqueued(ctx context.Context, destination string) (*FullText, error)

CreateJobForUnqueued creates a job associated with a single item for a single destination. It should be safe for multiple workers to use.

A potential problem is that occasionally a duplicate item key might be selected simultaneously by multiple workers. If that is the case, the database will still prevent the creation of a duplicate job for the same item and the same destination. This error could be safely ignored.

func (*Repo) GetFullText

func (r *Repo) GetFullText(ctx context.Context, id uuid.UUID) (*FullText, error)

GetFullText finds a full text job by ID from the repository

func (*Repo) GetReadyJob

func (r *Repo) GetReadyJob(ctx context.Context, destination string) (*FullText, error)

GetReadyJob gets a job for a particular destination that is available and marks it as started.

func (*Repo) SaveFullText

func (r *Repo) SaveFullText(ctx context.Context, job *FullText) error

SaveFullText serializes a job to the database

type Repository

type Repository interface {
	GetFullText(ctx context.Context, id uuid.UUID) (*FullText, error)
	SaveFullText(ctx context.Context, job *FullText) error
	CreateJobForUnqueued(ctx context.Context, destination string) (*FullText, error)
	GetReadyJob(ctx context.Context, destination string) (*FullText, error)
}

Repository is an interface describing a data store for jobs.

Jump to

Keyboard shortcuts

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