Documentation ¶
Overview ¶
Package database provides the persistence layer for jobs. It is a wrapper around an SQLite database, exposing the operations required by the application.
Index ¶
- Variables
- type Database
- func (db *Database) Begin() error
- func (db *Database) Close() error
- func (db *Database) Commit() error
- func (db *Database) JobCleanFinished() (int64, error)
- func (db *Database) JobDelete(j *job.Job) error
- func (db *Database) JobFinish(j *job.Job) error
- func (db *Database) JobGetAll() ([]job.Job, error)
- func (db *Database) JobGetByID(id int64) (*job.Job, error)
- func (db *Database) JobGetFinished(max int64) ([]job.Job, error)
- func (db *Database) JobGetPending(max int64) ([]job.Job, error)
- func (db *Database) JobGetRunning() ([]job.Job, error)
- func (db *Database) JobGetUnfinished() ([]job.Job, error)
- func (db *Database) JobStart(j *job.Job) error
- func (db *Database) JobSubmit(j *job.Job) error
- func (db *Database) Rollback() error
- type Pool
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyUpdate = errors.New("Update operation does not change any values")
ErrEmptyUpdate indicates that an update operation would not change any values.
var ErrInvalidSavepoint = errors.New("that save point does not exist")
ErrInvalidSavepoint is returned when a user of the Database uses an unkown (or expired) savepoint name.
var ErrInvalidValue = errors.New("Invalid value for parameter")
ErrInvalidValue indicates that one or more parameters passed to a method had values that are invalid for that operation.
var ErrNoTxInProgress = errors.New("There is no transaction in progress")
ErrNoTxInProgress indicates that an attempt was made to finish a transaction when none was active.
var ErrObjectNotFound = errors.New("object was not found in database")
ErrObjectNotFound indicates that an Object was not found in the database.
var ErrTxInProgress = errors.New("A Transaction is already in progress")
ErrTxInProgress indicates that an attempt to initiate a transaction failed because there is already one in progress.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database wraps the connection to the underlying data store and associated state.
func Open ¶
Open opens a Database. If the database specified by the path does not exist, yet, it is created and initialized.
func (*Database) Begin ¶
Begin begins an explicit database transaction. Only one transaction can be in progress at once, attempting to start one, while another transaction is already in progress will yield ErrTxInProgress.
func (*Database) Close ¶
Close closes the database. If there is a pending transaction, it is rolled back.
func (*Database) Commit ¶
Commit ends the active transaction, making any changes made during that transaction permanent and visible to other connections. If no transaction is active, it returns ErrNoTxInProgress
func (*Database) JobCleanFinished ¶
JobCleanFinished removes all finished Jobs from the database.
func (*Database) JobGetAll ¶
JobGetAll loads *all* Jobs from the database, regardless of age or status. Beware that this might be a lot.
func (*Database) JobGetByID ¶
JobGetByID looks up a Job by its ID. If no Job with the given ID exists, it is not considered an error, in that case (nil, nil) is returned.
func (*Database) JobGetFinished ¶
JobGetFinished returns the <max> most recently finished Jobs. Passing -1 for max means all of them.
func (*Database) JobGetPending ¶
JobGetPending returns up to <max> Jobs that have been submitted but not yet started.
func (*Database) JobGetRunning ¶
JobGetRunning returns the list of Jobs (possibly empty) that are currently being executed.
func (*Database) JobGetUnfinished ¶
JobGetUnfinished returns a slice of jobs that are currently running or enqueued to be run.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a pool of database connections
func NewPool ¶
NewPool creates a Pool of database connections. The number of connections to use is given by the parameter cnt.
func (*Pool) Close ¶
Close closes all open database connections currently in the pool and empties the pool. Any connections retrieved from the pool that are in use at the time Close is called are unaffected.
func (*Pool) Get ¶
Get returns a DB connection from the pool. If the pool is empty, it waits for a connection to be returned.
func (*Pool) GetNoWait ¶
GetNoWait returns a DB connection from the pool. If the pool is empty, it creates a new one.