-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob.go
46 lines (39 loc) · 1.07 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
44
45
46
package queuelite
import (
"database/sql"
"errors"
)
// JobState represents the state of a job in the queue.
type JobState string
const (
JobStatePending JobState = "pending"
JobStateRunning JobState = "running"
JobStateRetry JobState = "retry"
JobStateFailed JobState = "failed"
JobStateCompleted JobState = "completed"
)
var JobNotFoundErr = errors.New("job not found in the queue")
// Job represents a job in the queue.
type Job struct {
ID int64 `json:"id"`
State JobState `json:"state"`
Data []byte `json:"data"`
AddedAt int64 `json:"added_at"`
RetryCount int `json:"retry_count"`
FailureReason sql.NullString `json:"failure_reason"`
}
type JobCount struct {
Pending int `json:"pending"`
Running int `json:"running"`
Retry int `json:"retry"`
Failed int `json:"failed"`
Completed int `json:"completed"`
Total int `json:"total"`
}
// NewJob returns a [Job] instance.
func NewJob(data []byte) Job {
return Job{
Data: data,
State: JobStatePending,
}
}