-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy patherror.go
More file actions
64 lines (53 loc) · 2.43 KB
/
error.go
File metadata and controls
64 lines (53 loc) · 2.43 KB
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
package river
import (
"fmt"
"time"
"github.com/riverqueue/river/rivertype"
)
// ErrJobCancelledRemotely is a sentinel error indicating that the job was cancelled remotely.
var ErrJobCancelledRemotely = rivertype.ErrJobCancelledRemotely
// JobCancelError is the error type returned by JobCancel. It should not be
// initialized directly, but is returned from the [JobCancel] function and can
// be used for test assertions.
type JobCancelError = rivertype.JobCancelError
// JobCancel wraps err and can be returned from a Worker's Work method to cancel
// the job at the end of execution. Regardless of whether or not the job has any
// remaining attempts, this will ensure the job does not execute again.
func JobCancel(err error) error {
return rivertype.JobCancel(err)
}
// JobSnoozeError is the error type returned by JobSnooze. It should not be
// initialized directly, but is returned from the [JobSnooze] function and can
// be used for test assertions.
type JobSnoozeError = rivertype.JobSnoozeError
// JobSnooze can be returned from a Worker's Work method to cause the job to be
// tried again after the specified duration. This also has the effect of
// incrementing the job's MaxAttempts by 1, meaning that jobs can be repeatedly
// snoozed without ever being discarded.
//
// A special duration of zero can be used to make the job immediately available
// to be reworked. This may be useful in cases like where a long-running job is
// being interrupted on shutdown. Instead of returning a context cancelled error
// that'd schedule a retry for the future and count towards maximum attempts,
// the work function can return JobSnooze(0) and the job will be retried
// immediately the next time a client starts up.
//
// Panics if duration is < 0.
func JobSnooze(duration time.Duration) error {
return &rivertype.JobSnoozeError{Duration: duration}
}
// QueueAlreadyAddedError is returned when attempting to add a queue that has
// already been added to the Client.
type QueueAlreadyAddedError struct {
Name string
}
func (e *QueueAlreadyAddedError) Error() string {
return fmt.Sprintf("queue %q already added", e.Name)
}
func (e *QueueAlreadyAddedError) Is(target error) bool {
_, ok := target.(*QueueAlreadyAddedError)
return ok
}
// UnknownJobKindError is returned when a Client fetches and attempts to
// work a job that has not been registered on the Client's Workers bundle (using AddWorker).
type UnknownJobKindError = rivertype.UnknownJobKindError