Documentation
¶
Overview ¶
Package jobs provides job management for MongoDB via mgo.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type J ¶
type J struct {
// id is the unique job id.
ID bson.ObjectId `bson:"_id" json:"id"`
// Status is the current status of the job.
Status Status `json:"status"`
// Tries holds history of attempts.
Tries []*Try `json:"tries"`
// Created is when the job was created.
Created time.Time `json:"created"`
// RunAt is the time this job should run at (or after).
RunAt time.Time `json:"runat" bson:"runat"`
// Data is the user data for this job.
Data map[string]interface{} `json:"data" bson:"data"`
// Retries is the number of remaining attempts that will
// be made to run this job.
Retries int
// RetryInterval is the time to wait after a failure before
// trying to run the job again.
RetryInterval time.Duration
// Kind is the kind for this job. Only runners with the same kind
// will be asked to process this job.
Kind string
}
J is a job.
type Runner ¶
Runner runs jobs.
func NewRunner ¶
NewRunner makes a new Runner capable of running jobs. The name should be unique across a system. The mgo.Collection is where the job records live in MongoDB. The kind string should match J.Kind values for jobs that this runner should execute.
type Status ¶
type Status int8
Status is the status of a job.
const ( // StatusInvalid represents invalid status values. StatusInvalid Status = iota // StatusNew means a job has just been created. StatusNew // StatusWorking means the job is being worked on. StatusWorking // StatusWaiting means the job is waiting to retry. StatusWaiting // StatusSuccess means the job was successful. StatusSuccess // StatusFailed means the job failed. StatusFailed )
func (Status) MarshalText ¶
MarshalText marshals the value into bytes.
func (*Status) UnmarshalText ¶
UnmarshalText unmarshals the bytes into the value.
type Try ¶
type Try struct {
// Runner is the name of the runner that tried to
// run this job.
Runner string `json:"runner" bson:"runner"`
// When is a timestamp of when the attempt took place.
When time.Time `json:"when" bson:"when"`
// Err is the error that was returned by JobFunc.
Err string `json:"err,omitempty" bson:"err,omitempty"`
}
Try contains details of an attempt to run a job.
Click to show internal directories.
Click to hide internal directories.
