You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+63Lines changed: 63 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -157,3 +157,66 @@ Specify an error-handler function. Default logs to stderr
157
157
### fatal
158
158
159
159
Specify a fatal error-handler function. Default logs to stderr and exits
160
+
161
+
### maxAttempts
162
+
163
+
Maximum number of attempts for a task before it's considered failed. Default is 1. If a task fails, it will be retried up to this many times.
164
+
165
+
```typescript
166
+
exportconst addQueue =newQueue<AddTask, number>({
167
+
name: 'add-queue',
168
+
callback: async (task:AddTask) =>task.a+task.b,
169
+
maxAttempts: 3,
170
+
});
171
+
```
172
+
173
+
## Task Options
174
+
175
+
When pushing tasks to the queue, you can specify additional options:
176
+
177
+
### schedule
178
+
179
+
Schedule a task to run at a specific time in the future, with optional expiration. The task will not run until the scheduled time, and will be discarded if it expires.
180
+
181
+
`src/add-queue.ts`
182
+
```typescript
183
+
exportinterfaceAddTask {
184
+
a:number;
185
+
b:number;
186
+
}
187
+
188
+
exportconst addQueue =newQueue<AddTask, number>({
189
+
name: 'add-queue',
190
+
callback: async (task:AddTask) =>task.a+task.b,
191
+
});
192
+
```
193
+
194
+
`src/index.ts`
195
+
```typescript
196
+
import { AddTask, addQueue } from'./add-queue';
197
+
198
+
if (addQueue.isMainThread()) {
199
+
// Schedule a task to run in 5 minutes
200
+
const sum =awaitaddQueue.await({
201
+
data: { a: 4, b: 8 },
202
+
schedule: {
203
+
scheduledAt: newDate(Date.now() +5*60*1000),
204
+
}
205
+
});
206
+
207
+
console.log('Sum is', sum);
208
+
// Sum is 12
209
+
210
+
// Schedule a task to run in 5 minutes, but expire after 10 minutes
0 commit comments