forked from fireworq/fireworq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.go
111 lines (88 loc) · 1.86 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package mysql
import (
"time"
"github.com/fireworq/fireworq/jobqueue"
"github.com/fireworq/fireworq/jobqueue/logger"
)
// incomingJob : implements the following interfaces
// - jobqueue.IncomingJob
// - jobqueue.Job
// - logger.LoggableJob
type incomingJob struct {
jobqueue.IncomingJob
id uint64
}
func (j *incomingJob) ID() uint64 {
return j.id
}
func (j *incomingJob) FailCount() uint {
return 0
}
func (j *incomingJob) Status() string {
return "claimed"
}
func (j *incomingJob) CreatedAt() uint64 {
return uint64(time.Now().UnixNano() / int64(time.Millisecond))
}
func (j *incomingJob) NextDelay() uint64 {
return j.IncomingJob.NextDelay()
}
func (j *incomingJob) NextTry() uint64 {
nowMillisecond := uint64(time.Now().UnixNano() / int64(time.Millisecond))
return nowMillisecond + j.NextDelay()
}
func (j *incomingJob) ToLoggable() logger.LoggableJob {
return j
}
// job : implements the following interfaces
// - jobqueue.Job
// - logger.LoggableJob
type job struct {
id uint64
category string
url string
payload string
status string
createdAt uint64 // milliseconds
nextTry uint64 // milliseconds
timeout uint // seconds
retryDelay uint // seconds
retryCount uint
failCount uint
}
func (j *job) ID() uint64 {
return j.id
}
func (j *job) Category() string {
return j.category
}
func (j *job) URL() string {
return j.url
}
func (j *job) Payload() string {
return j.payload
}
func (j *job) NextTry() uint64 {
return j.nextTry
}
func (j *job) RetryCount() uint {
return j.retryCount
}
func (j *job) RetryDelay() uint {
return j.retryDelay
}
func (j *job) FailCount() uint {
return j.failCount
}
func (j *job) Timeout() uint {
return j.timeout
}
func (j *job) Status() string {
return j.status
}
func (j *job) CreatedAt() uint64 {
return j.createdAt
}
func (j *job) ToLoggable() logger.LoggableJob {
return j
}