Skip to content

Commit b47e7c8

Browse files
fix: resolve lint errors
1 parent e0f18a4 commit b47e7c8

28 files changed

Lines changed: 51 additions & 932 deletions

docs/api-reference.md

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,6 @@
22
title: API Reference
33
description: Complete API reference for all bun-queue classes and methods.
44
---
5-
|----------|------|-------------|
6-
| `name` | `string` | Queue name |
7-
| `prefix` | `string` | Redis key prefix |
8-
| `redisClient` | `RedisClient` | Redis client instance |
9-
| `keyPrefix` | `string` | Full key prefix (`prefix:name`) |
10-
| `events` | `JobEvents` | Event emitter |
11-
12-
### Methods
13-
14-
#### Job Operations
15-
16-
```typescript
17-
// Add a job to the queue
18-
await queue.add(data: T, options?: JobOptions): Promise<Job<T>>
19-
20-
// Get a job by ID
21-
await queue.getJob(jobId: string): Promise<Job<T> | null>
22-
23-
// Get jobs by status
24-
await queue.getJobs(status: JobStatus, start?: number, end?: number): Promise<Job<T>[]>
25-
26-
// Get job counts for all statuses
27-
await queue.getJobCounts(): Promise<Record<JobStatus, number>>
28-
29-
// Remove a job
30-
await queue.removeJob(jobId: string): Promise<void>
31-
32-
// Bulk remove jobs
33-
await queue.bulkRemove(jobIds: string[]): Promise<number>
34-
```
35-
36-
#### Processing
37-
38-
```typescript
39-
// Process jobs with handler and concurrency
40-
queue.process(concurrency: number, handler: (job: Job<T>) => Promise<any>): void
41-
42-
// Process with distributed lock
43-
await queue.processJobWithLock(jobId: string, handler: (job: Job<T>) => Promise<any>): Promise<any>
44-
```
45-
46-
#### Queue Controls
47-
48-
```typescript
49-
await queue.pause(): Promise<void>
50-
await queue.resume(): Promise<void>
51-
await queue.empty(): Promise<void>
52-
await queue.close(): Promise<void>
53-
await queue.ping(): Promise<boolean>
54-
55-
// Bulk operations
56-
await queue.bulkPause(jobIds: string[]): Promise<number>
57-
await queue.bulkResume(jobIds: string[]): Promise<number>
58-
```
59-
60-
#### Rate Limiting
61-
62-
```typescript
63-
await queue.isRateLimited(key?: string, data?: T): Promise<{ limited: boolean, resetIn: number }>
64-
```
65-
66-
#### Cron Jobs
675

686
```typescript
697
await queue.scheduleCron(options: CronJobOptions): Promise<string>

docs/config.md

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,6 @@ title: Configuration File
33
description: Configure bun-queue using a configuration file.
44
---
55

6-
// Key prefix for all Redis keys (default: 'queue')
7-
prefix: 'myapp',
8-
9-
// Logging
10-
logLevel: 'info', // 'debug' | 'info' | 'warn' | 'error' | 'silent'
11-
12-
// Default options applied to every job
13-
defaultJobOptions: {
14-
attempts: 3,
15-
backoff: { type: 'exponential', delay: 2000 },
16-
removeOnComplete: 100,
17-
removeOnFail: false,
18-
timeout: 30000,
19-
},
20-
21-
// Rate limiting
22-
limiter: {
23-
max: 1000,
24-
duration: 60000,
25-
},
26-
27-
// Metrics collection
28-
metrics: {
29-
enabled: true,
30-
collectInterval: 10000,
31-
},
32-
33-
// Stalled job detection
34-
stalledJobCheckInterval: 30000,
35-
maxStalledJobRetries: 3,
36-
37-
// Distributed locking (default: true)
38-
distributedLock: true,
39-
40-
// Dead letter queue
41-
defaultDeadLetterOptions: {
42-
enabled: true,
43-
queueSuffix: '-dead-letter',
44-
maxRetries: 5,
45-
removeFromOriginalQueue: true,
46-
},
47-
48-
// Horizontal scaling
49-
horizontalScaling: {
50-
enabled: true,
51-
instanceId: process.env.INSTANCE_ID,
52-
maxWorkersPerInstance: 10,
53-
jobsPerWorker: 5,
54-
leaderElection: {
55-
heartbeatInterval: 5000,
56-
leaderTimeout: 30000,
57-
},
58-
workCoordination: {
59-
pollInterval: 1000,
60-
},
61-
},
62-
})
63-
```
64-
65-
## Options Reference
66-
676
### `QueueConfig`
687

698
| Option | Type | Default | Description |

docs/configuration.md

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,8 @@
22
title: Queue Configuration
33
description: Configure bun-queue with various options for Redis, rate limiting, metrics, and more.
44
---
5-
})
6-
```
7-
8-
## Redis Configuration
9-
10-
### Connection String
11-
12-
```typescript
13-
const queue = new Queue('tasks', {
14-
redis: {
15-
url: 'redis://localhost:6379'
16-
}
17-
})
18-
```
19-
20-
### Custom Redis Client
215

226
```typescript
23-
const queue = new Queue('tasks', {
24-
redis: {
25-
client: myRedisClient // Provide your own client
26-
}
27-
})
28-
```
29-
30-
### Environment Variables
31-
32-
bun-queue reads these environment variables:
33-
34-
- `REDIS_URL`: Redis connection string (default: `redis://localhost:6379`)
35-
36-
```bash
37-
38-
# .env
39-
40-
REDIS_URL=redis://localhost:6379
41-
```
42-
43-
## Default Job Options
44-
45-
Set default options for all jobs in a queue:
46-
47-
```typescript
48-
const queue = new Queue('tasks', {
49-
defaultJobOptions: {
50-
attempts: 5,
51-
backoff: {
52-
type: 'exponential',
53-
delay: 5000
54-
},
55-
removeOnComplete: true,
56-
removeOnFail: false,
57-
timeout: 60000
58-
}
59-
})
60-
```
61-
62-
## Rate Limiting
63-
64-
Configure rate limiting to control job processing speed:
65-
66-
```typescript
67-
const queue = new Queue('api-calls', {
68-
limiter: {
69-
max: 100, // Maximum jobs per duration
70-
duration: 60000, // Duration in milliseconds (1 minute)
71-
keyPrefix: (data) => data.userId // Optional: rate limit per key
727
}
738
})
749
```

docs/creating-jobs.md

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,8 @@
22
title: Creating Jobs
33
description: Learn how to create and add jobs to the queue with various options.
44
---
5-
})
6-
7-
console.log(`Job ${job.id} added to the queue`)
8-
```
9-
10-
## Job Options
11-
12-
Jobs support various options to control their behavior:
13-
14-
```typescript
15-
await queue.add(
16-
{ task: 'process-pdf', url: 'https://example.com/document.pdf' },
17-
{
18-
delay: 5000, // Delay for 5 seconds before processing
19-
attempts: 3, // Retry up to 3 times on failure
20-
backoff: {
21-
type: 'exponential', // 'fixed' or 'exponential' backoff
22-
delay: 1000, // Base delay in milliseconds
23-
},
24-
priority: 10, // Higher number = higher priority
25-
removeOnComplete: true, // Remove job when completed
26-
lifo: false, // Process in FIFO order (default)
27-
jobId: 'custom-id', // Provide a custom job ID
28-
timeout: 30000, // Job timeout in milliseconds
29-
}
30-
)
31-
```
32-
33-
## Delayed Jobs
34-
35-
Schedule jobs to run after a specific delay:
36-
37-
```typescript
38-
// Add a job that will be processed after 30 seconds
39-
await queue.add(
40-
{ task: 'send-reminder', userId: 123 },
41-
{ delay: 30000 }
42-
)
43-
44-
// Schedule a job for a specific time
45-
const futureTime = new Date('2024-12-25T10:00:00').getTime()
46-
const delay = futureTime - Date.now()
47-
48-
await queue.add(
49-
{ task: 'send-christmas-greeting' },
50-
{ delay }
51-
)
52-
```
53-
54-
## Job Dependencies
55-
56-
Jobs can depend on other jobs and will only run after their dependencies complete:
575

586
```typescript
59-
// First job - create report data
60-
const dataJob = await queue.add({
61-
task: 'generate-report-data',
62-
reportId: 'monthly-sales'
63-
})
64-
65-
// Second job - depends on first job
66-
const pdfJob = await queue.add(
67-
{ task: 'generate-pdf', reportId: 'monthly-sales' },
68-
{ dependsOn: dataJob.id }
69-
)
70-
717
// Third job - depends on multiple jobs
728
const emailJob = await queue.add(
739
{ task: 'send-report-email', reportId: 'monthly-sales' },

docs/cron-jobs.md

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,8 @@
22
title: Cron Jobs
33
description: Schedule recurring jobs using cron expressions.
44
---
5-
}
6-
})
7-
8-
console.log(`Scheduled cron job: ${jobId}`)
9-
```
10-
11-
## Cron Expression Format
12-
13-
Standard 5-field cron expression:
14-
15-
```ts
16-
┌───────────── minute (0-59)
17-
│ ┌───────────── hour (0-23)
18-
│ │ ┌───────────── day of month (1-31)
19-
│ │ │ ┌───────────── month (1-12)
20-
│ │ │ │ ┌───────────── day of week (0-6, 0=Sunday)
21-
│ │ │ │ │
22-
23-
* * * * *
24-
25-
```
26-
27-
### Examples
285

296
```typescript
30-
// Every minute
31-
'* * * * *'
32-
33-
// Every hour at minute 0
34-
'0 * * * *'
35-
36-
// Every day at 9:30 AM
37-
'30 9 * * *'
38-
39-
// Every Monday at 8:00 AM
40-
'0 8 * * 1'
41-
42-
// Every weekday (Monday-Friday) at 8:00 AM
43-
'0 8 * * 1-5'
44-
45-
// First Monday of every month at 12:00 PM
46-
'0 12 1-7 * 1'
47-
48-
// Every 5 minutes
49-
'*/5 * * * *'
50-
51-
// Every 2 hours
52-
'0 */2 * * *'
53-
```
54-
55-
## Cron Job Options
56-
57-
```typescript
58-
await queue.scheduleCron({
59-
// Required: Cron expression
60-
cronExpression: '0 * * * *',
61-
62-
// Required: Job data
63-
data: { task: 'hourly-update' },
64-
65-
// Optional: Custom job ID
66-
jobId: 'hourly-update-job',
67-
68-
// Optional: Timezone (default: system timezone)
69-
timezone: 'America/New*York',
70-
717
// Optional: Maximum number of executions
728
limit: 100,
739

0 commit comments

Comments
 (0)