0
0
NestJSframework~10 mins

Job options (delay, attempts, priority) in NestJS - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Job options (delay, attempts, priority)
Create Job with Options
Set delay timer?
YesWait delay ms
Delay expires
Add job to queue
Start job processing
Process job
Job succeeds
Check attempts left
Done
No Yes
Fail
Process job again
This flow shows how a job is created with options like delay, attempts, and priority, then processed with retries if it fails.
Execution Sample
NestJS
queue.add('email', { to: 'user@example.com' }, { delay: 5000, attempts: 3, priority: 2 });
Adds an email job to the queue with a 5-second delay, up to 3 retry attempts, and priority level 2.
Execution Table
StepActionDelay TimerAttempts LeftPriorityJob Status
1Job created with options5000 ms32Waiting
2Delay expires after 5000 ms0 ms32Ready to process
3Job processing starts0 ms32Processing
4Job fails0 ms22Retrying
5Job processing retry 10 ms22Processing
6Job fails again0 ms12Retrying
7Job processing retry 20 ms12Processing
8Job succeeds0 ms12Completed
💡 Job succeeds at step 8 or fails after all attempts are used.
Variable Tracker
VariableStartAfter Step 2After Step 4After Step 6After Step 8
delay50000000
attempts33211
priority22222
jobStatusWaitingReady to processRetryingRetryingCompleted
Key Moments - 3 Insights
Why does the job wait before processing?
Because the delay option is set to 5000 ms, the job waits that time before starting processing, as shown in execution_table step 2.
What happens when a job fails but has attempts left?
The job retries processing, decreasing attempts by 1 each time, as seen in steps 4 and 6 where attempts go from 3 to 2 and then 1.
Does priority affect retry attempts?
No, priority stays the same during retries and only affects job order in the queue, not the number of attempts, as shown in variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the jobStatus at step 3?
AProcessing
BWaiting
CRetrying
DCompleted
💡 Hint
Check the 'Job Status' column in execution_table row with Step 3.
At which step does the delay timer reach zero?
AStep 1
BStep 2
CStep 4
DStep 8
💡 Hint
Look at the 'Delay Timer' column in execution_table to find when it changes from 5000 ms to 0 ms.
If attempts were set to 1 initially, how many retries would the job have?
A3 retries
B1 retry
CNo retries
D2 retries
💡 Hint
Refer to the 'Attempts Left' column in variable_tracker and how it decreases on failure.
Concept Snapshot
Job options in NestJS queues:
- delay: wait before processing (ms)
- attempts: retry count on failure
- priority: job order in queue
Jobs wait delay, then process.
Failures retry until attempts run out.
Full Transcript
This visual execution shows how NestJS job options delay, attempts, and priority work. A job is created with these options. The delay causes the job to wait before processing. When processing starts, if the job fails, it retries until attempts are used up. Priority affects job order but not retries. The execution table tracks each step, showing delay timer, attempts left, priority, and job status. Variable tracker shows how these values change over time. Key moments clarify common confusions about delay waiting, retry logic, and priority's role. The quiz tests understanding by referencing specific steps and variable states.