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 ¶
- Variables
- type FullText
- type Repo
- func (r *Repo) CreateJobForUnqueued(ctx context.Context, destination string) (*FullText, error)
- func (r *Repo) GetFullText(ctx context.Context, id uuid.UUID) (*FullText, error)
- func (r *Repo) GetReadyJob(ctx context.Context, destination string) (*FullText, error)
- func (r *Repo) SaveFullText(ctx context.Context, job *FullText) error
- type Repository
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo is a data store using PostgreSQL with the pgx native interface.
func NewJobsRepo ¶
NewJobsRepo returns an item repo using PostgreSQL with the pgx native interface.
func (*Repo) CreateJobForUnqueued ¶
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 ¶
GetFullText finds a full text job by ID from the repository
func (*Repo) GetReadyJob ¶
GetReadyJob gets a job for a particular destination that is available and marks it as started.
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.