| 22 | } |
| 23 | |
| 24 | async addJob( |
| 25 | job: Omit<Job<T>, "id" | "options"> & { |
| 26 | options?: OptionalJobOptions |
| 27 | id?: string |
| 28 | } |
| 29 | ) { |
| 30 | const id = job.id ?? crypto.randomUUID() |
| 31 | if ( |
| 32 | (job.options?.retry?.totalAttempts ?? 0) >= |
| 33 | (job.options?.retry?.maxAttempts ?? 1) |
| 34 | ) { |
| 35 | return id |
| 36 | } |
| 37 | |
| 38 | await this.push({ |
| 39 | ...job, |
| 40 | id, |
| 41 | options: { |
| 42 | delay: job.options?.delay ?? 0, |
| 43 | priority: job.options?.priority ?? 0, |
| 44 | retry: { |
| 45 | totalAttempts: job.options?.retry?.totalAttempts ?? 0, |
| 46 | maxAttempts: |
| 47 | job.options?.retry?.maxAttempts ?? this.options.retryAttempts, |
| 48 | delay: job.options?.retry?.delay ?? this.options.retryDelay, |
| 49 | }, |
| 50 | }, |
| 51 | }) |
| 52 | |
| 53 | return id |
| 54 | } |
| 55 | |
| 56 | protected abstract push( |
| 57 | job: Job<T> & { options: { retry: Required<Job<T>["options"]["retry"]> } } |