forked from vgarvardt/gue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
67 lines (53 loc) · 1.58 KB
/
error.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
package gue
import (
"fmt"
"time"
)
// ErrJobReschedule interface implementation allows errors to reschedule jobs in the individual basis.
type ErrJobReschedule interface {
rescheduleJobAt() time.Time
}
type errJobRescheduleIn struct {
d time.Duration
s string
}
// ErrRescheduleJobIn spawns an error that reschedules a job to run after some predefined duration.
func ErrRescheduleJobIn(d time.Duration, reason string) error {
return errJobRescheduleIn{d: d, s: reason}
}
// Error implements error.Error()
func (e errJobRescheduleIn) Error() string {
return fmt.Sprintf("rescheduling job in %q because %q", e.d.String(), e.s)
}
func (e errJobRescheduleIn) rescheduleJobAt() time.Time {
return time.Now().Add(e.d)
}
type errJobRescheduleAt struct {
t time.Time
s string
}
// ErrRescheduleJobAt spawns an error that reschedules a job to run at some predefined time.
func ErrRescheduleJobAt(t time.Time, reason string) error {
return errJobRescheduleAt{t: t, s: reason}
}
// Error implements error.Error()
func (e errJobRescheduleAt) Error() string {
return fmt.Sprintf("rescheduling job at %q because %q", e.t.String(), e.s)
}
func (e errJobRescheduleAt) rescheduleJobAt() time.Time {
return e.t
}
type errJobDiscard struct {
s string
}
// ErrDiscardJob spawns an error that unconditionally discards a job.
func ErrDiscardJob(reason string) error {
return errJobDiscard{s: reason}
}
// Error implements error.Error()
func (e errJobDiscard) Error() string {
return fmt.Sprintf("discarding job because %q", e.s)
}
func (e errJobDiscard) rescheduleJobAt() time.Time {
return time.Time{}
}