Skip to content

Commit ebde9e8

Browse files
committed
add options documentation to readme
1 parent 32a1326 commit ebde9e8

2 files changed

Lines changed: 88 additions & 3 deletions

File tree

README.md

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ This queuer is meant to be as easy as possible to use. No specific function sign
1212

1313
The job table contains only queued, scheduled and running tasks. The ended jobs (succeeded, cancelled, failed) are moved to a timescaleDB table.
1414

15+
---
16+
1517
## Getting started
1618

1719
The full initialisation is (in the easiest case):
@@ -50,4 +52,87 @@ QUEUER_DB_PASSWORD=password1234
5052
QUEUER_DB_SCHEMA=public
5153
```
5254

53-
You can find a full example (the same as above plus a more detailed example) in the example folder. In there you'll also find a docker-compose file with the timescaleDB/postgres service that is needed for the running the queuer (it's just postgres with an extension).
55+
You can find a full example (the same as above plus a more detailed example) in the example folder. In there you'll also find a docker-compose file with the timescaleDB/postgres service that is needed for the running the queuer (it's just postgres with an extension).
56+
57+
---
58+
59+
## Worker Options
60+
61+
The OnError struct defines how a worker should handle errors when processing a job. This allows for configurable retry behavior.
62+
63+
```go
64+
type OnError struct {
65+
Timeout float64 `json:"timeout"`
66+
MaxRetries int `json:"max_retries"`
67+
RetryDelay float64 `json:"retry_delay"`
68+
RetryBackoff string `json:"retry_backoff"`
69+
}
70+
```
71+
72+
- `Timeout`: The maximum time (in seconds) allowed for a single attempt of a job. If the job exceeds this duration, it's considered to have timed out.
73+
- `MaxRetries`: The maximum number of times a job will be retried after a failure.
74+
- `RetryDelay`: The initial delay (in seconds) before the first retry attempt. This delay can be modified by the `RetryBackoff` strategy.
75+
- `RetryBackoff`: Specifies the strategy used to increase the delay between subsequent retries.
76+
77+
---
78+
79+
## Job options
80+
81+
Job Options
82+
The Options struct allows you to define specific behaviors for individual jobs, overriding default worker settings where applicable.
83+
84+
```go
85+
type Options struct {
86+
OnError *OnError
87+
Schedule *Schedule
88+
}
89+
```
90+
91+
- `OnError`: An optional `OnError` configuration that will override the worker's default error handling for this specific job. This allows you to define unique retry logic per job.
92+
- `Schedule`: An optional `Schedule` configuration for jobs that need to be executed at recurring intervals.
93+
94+
### OnError for jobs
95+
96+
OnError for Jobs
97+
The OnError struct for jobs is identical to the one used for worker options, allowing granular control over error handling for individual jobs.
98+
99+
```go
100+
type OnError struct {
101+
Timeout float64 `json:"timeout"`
102+
MaxRetries int `json:"max_retries"`
103+
RetryDelay float64 `json:"retry_delay"`
104+
RetryBackoff string `json:"retry_backoff"`
105+
}
106+
```
107+
108+
#### Retry Backoff Strategies
109+
110+
The RetryBackoff constant defines the available strategies for increasing retry delays:
111+
112+
```go
113+
const (
114+
RETRY_BACKOFF_NONE = "none"
115+
RETRY_BACKOFF_LINEAR = "linear"
116+
RETRY_BACKOFF_EXPONENTIAL = "exponential"
117+
)
118+
```
119+
120+
- `RETRY_BACKOFF_NONE`: No backoff. The RetryDelay remains constant for all retries.
121+
- `RETRY_BACKOFF_LINEAR`: The retry delay increases linearly with each attempt (e.g., delay, 2*delay, 3*delay).
122+
- `RETRY_BACKOFF_EXPONENTIAL`: The retry delay increases exponentially with each attempt (e.g., delay, delay*2, delay*2*2).
123+
124+
### Schedule
125+
126+
The Schedule struct is used to define recurring jobs.
127+
128+
```go
129+
type Schedule struct {
130+
Start time.Time `json:"start"`
131+
Interval time.Duration `json:"interval"`
132+
MaxCount int `json:"max_count"`
133+
}
134+
```
135+
136+
- `Start`: The initial time at which the scheduled job should first run.
137+
- `Interval`: The duration between consecutive executions of the scheduled job.
138+
- `MaxCount`: The maximum number of times the job should be executed. A value 0 indicates an indefinite number of repetitions (run forever).

model/optionsSchedule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func (c *Schedule) IsValid() error {
1818
if c.Start.IsZero() {
1919
return errors.New("start time cannot be zero")
2020
}
21-
if c.MaxCount < 1 {
22-
return errors.New("maxCount must be greater than or equal to 1")
21+
if c.MaxCount < 0 {
22+
return errors.New("maxCount must be greater than or equal to 0")
2323
}
2424
if c.Interval <= time.Duration(0) && c.NextInterval == nil {
2525
return errors.New("interval must be greater than zero or nextInterval must be provided")

0 commit comments

Comments
 (0)