-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob.go
43 lines (36 loc) · 1.17 KB
/
job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package gorqs
import "errors"
var (
// Predefined errors
ErrPending = errors.New("gorqs: pending into queue")
ErrRunning = errors.New("gorqs: job still running")
ErrNotFound = errors.New("gorqs: job not found")
ErrInvalid = errors.New("gorqs: found non error result")
ErrQueueClosed = errors.New("gorqs: queue is closed")
ErrTimeout = errors.New("gorqs: operation took too long")
ErrUnknownMode = errors.New("gorqs: unknown queue mode flag")
ErrInvalidMode = errors.New("gorqs: invalid queue mode flag")
ErrNotImplemented = errors.New("gorqs: feature not enabled. add TrackJobs flag when creating the queue")
)
// Runner represents a runnable job expected by the queue service.
type Runner interface {
Run() error
}
// jobber defines expected real job behaviors.
type jobber interface {
getID() int64
Runner
}
// job represents the concrete item that will be pushed and processed the by the queue service.
type job struct {
id int64
r Runner
}
// getID returns a given job unique id.
func (j *job) getID() int64 {
return j.id
}
// Run implements the Run method of Runner interface.
func (j *job) Run() error {
return j.r.Run()
}