-
Notifications
You must be signed in to change notification settings - Fork 104
/
result.go
59 lines (49 loc) · 1.59 KB
/
result.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
package jobqueue
const (
// ResultStatusSuccess means that the job is successfully processed.
ResultStatusSuccess = "success"
// ResultStatusFailure means that the job is failed but it may be retried.
ResultStatusFailure = "failure"
// ResultStatusPermanentFailure means that the job is failed and
// should never be retried.
ResultStatusPermanentFailure = "permanent-failure"
// ResultStatusInternalFailure means that the job is failed before
// processing it in some internal reason.
ResultStatusInternalFailure = "internal-failure"
)
// Result describes the result of a processed job.
type Result struct {
Status string `json:"status"`
Code int `json:"code"`
Message string `json:"message"`
}
// IsSuccess returns if the job succeeded
func (rslt *Result) IsSuccess() bool {
return rslt.Status == ResultStatusSuccess
}
// IsFailure returns if the job is successfully processed or not.
func (rslt *Result) IsFailure() bool {
return rslt.Status != ResultStatusSuccess
}
// IsPermanentFailure returns if the job is permanently failed.
func (rslt *Result) IsPermanentFailure() bool {
return rslt.Status == ResultStatusPermanentFailure
}
// IsFinished returns if the job can be retried or not.
func (rslt *Result) IsFinished() bool {
switch rslt.Status {
case ResultStatusSuccess, ResultStatusPermanentFailure:
return true
default:
return false
}
}
// IsValid returns if the result status is valid or not.
func (rslt *Result) IsValid() bool {
switch rslt.Status {
case ResultStatusSuccess, ResultStatusFailure, ResultStatusPermanentFailure:
return true
default:
return false
}
}