-
Notifications
You must be signed in to change notification settings - Fork 104
/
inspector.go
87 lines (76 loc) · 2.67 KB
/
inspector.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
package jobqueue
import (
"encoding/json"
"time"
)
// InspectedJob describes a job in a queue.
type InspectedJob struct {
ID uint64 `json:"id"`
Category string `json:"category"`
URL string `json:"url"`
Payload json.RawMessage `json:"payload,omitempty"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
NextTry time.Time `json:"next_try"`
Timeout uint `json:"timeout"`
FailCount uint `json:"fail_count"`
MaxRetries uint `json:"max_retries"`
RetryDelay uint `json:"retry_delay"`
}
// InspectedJobs describes a (page of) job list in a queue.
type InspectedJobs struct {
Jobs []InspectedJob `json:"jobs"`
NextCursor string `json:"next_cursor"`
}
// SortOrder describes sort order at inspecting jobs.
type SortOrder int
// Sort orders
const (
Asc SortOrder = iota
Desc
)
// Inspector is an interface to inspect jobs in a queue.
type Inspector interface {
Delete(jobID uint64) error
Find(jobID uint64) (*InspectedJob, error)
FindAllGrabbed(limit uint, cursor string, order SortOrder) (*InspectedJobs, error)
FindAllWaiting(limit uint, cursor string, order SortOrder) (*InspectedJobs, error)
FindAllDeferred(limit uint, cursor string, order SortOrder) (*InspectedJobs, error)
}
// HasInspector is an interface describing that it has an Inspector.
//
// This is typically a JobQueue sub-interface.
type HasInspector interface {
Inspector() Inspector
}
// FailedJob describes a (permanently) failed job that was in a queue.
type FailedJob struct {
ID uint64 `json:"id"`
JobID uint64 `json:"job_id"`
Category string `json:"category"`
URL string `json:"url"`
Payload json.RawMessage `json:"payload,omitempty"`
Result *Result `json:"result"`
FailCount uint `json:"fail_count"`
FailedAt time.Time `json:"failed_at"`
CreatedAt time.Time `json:"created_at"`
}
// FailedJobs describes a (page of) failed job list of a queue.
type FailedJobs struct {
FailedJobs []FailedJob `json:"failed_jobs"`
NextCursor string `json:"next_cursor"`
}
// FailureLog is an interface to inspect failed jobs of a queue.
type FailureLog interface {
Add(failed Job, result *Result) error
Delete(failureID uint64) error
Find(failureID uint64) (*FailedJob, error)
FindAll(limit uint, cursor string) (*FailedJobs, error)
FindAllRecentFailures(limit uint, cursor string) (*FailedJobs, error)
}
// HasFailureLog is an interface describing that it has an FailureLog.
//
// This is typically a JobQueue sub-interface.
type HasFailureLog interface {
FailureLog() FailureLog
}