The delay option sets a time in milliseconds to wait before the job starts processing. It schedules the job to run after the delay period.
Click to reveal answer
beginner
How does the attempts option affect job processing in NestJS?
The attempts option defines how many times a job will retry if it fails. This helps handle temporary errors by retrying automatically.
Click to reveal answer
beginner
What is the purpose of the priority option in NestJS jobs?
The priority option sets the job's importance level. Jobs with higher priority run before lower priority ones, helping manage urgent tasks first.
Click to reveal answer
intermediate
How would you set a job to retry 5 times with a 10-second delay before starting in NestJS?
You set attempts: 5 and delay: 10000 (milliseconds) in the job options when adding the job.
Click to reveal answer
intermediate
Why is setting job priority useful in a queue system?
Priority helps the system decide which jobs to run first, so urgent or important tasks don't wait behind less important ones. This improves efficiency and user experience.
Click to reveal answer
What does the delay option specify in a NestJS job?
AMaximum job execution time
BNumber of retry attempts
CJob importance level
DTime to wait before starting the job
✗ Incorrect
The delay option sets how long to wait before the job starts processing.
If a job fails, which option controls how many times it will retry?
Aattempts
Bdelay
Cpriority
Dtimeout
✗ Incorrect
The attempts option defines the number of retry tries for a failed job.
Which job option helps run urgent jobs before others?
Apriority
Bdelay
Cattempts
Drepeat
✗ Incorrect
The priority option sets the job's importance to run urgent jobs first.
How do you specify a 5-second delay before a job starts?
Aattempts: 5
Bdelay: 5000
Cpriority: 5
Dtimeout: 5000
✗ Incorrect
Delay is set in milliseconds, so 5000 means 5 seconds.
What happens if you set attempts to 1?
AJob will retry once on failure
BJob will run twice in parallel
CJob will never retry on failure
DJob will delay 1 second before starting
✗ Incorrect
Setting attempts: 1 means only one attempt total; the job will never retry on failure.
Explain how the delay, attempts, and priority options work together in NestJS job processing.
Think about scheduling, retrying, and ordering jobs.
You got /3 concepts.
Describe a real-life scenario where you would use job priority and delay options in a NestJS queue.
Imagine managing tasks with different urgency and timing.
You got /3 concepts.
Practice
(1/5)
1. In NestJS job queues, what does the delay option do when adding a job?
easy
A. It sets the maximum number of retries for the job.
B. It postpones the job execution by a specified time.
C. It assigns the job a priority level.
D. It cancels the job immediately.
Solution
Step 1: Understand the purpose of delay in job options
The delay option is used to postpone when a job starts running after being added to the queue.
Step 2: Compare with other options
attempts controls retries, priority controls order, so they do not delay execution.
Final Answer:
It postpones the job execution by a specified time. -> Option B
Quick Check:
delay = postpone job start [OK]
Hint: Delay means wait before running the job [OK]
Common Mistakes:
Confusing delay with attempts (retry count)
Thinking delay sets job priority
Assuming delay cancels the job
2. Which of the following is the correct way to add a job with 3 retry attempts and a 5-second delay in NestJS?
easy
A. queue.add('jobName', data, { retries: 3, wait: 5000 })
B. queue.add('jobName', data, { delay: 3, attempts: 5000 })
C. queue.add('jobName', data, { attempts: '3', delay: '5000' })
D. queue.add('jobName', data, { attempts: 3, delay: 5000 })
Solution
Step 1: Identify correct option keys and values
The correct keys are attempts for retries and delay for postponing in milliseconds.
Step 2: Check value types and order
Values must be numbers, not strings. queue.add('jobName', data, { attempts: 3, delay: 5000 }) uses correct keys and numeric values.
A. The attempts option is invalid and should be removed.
B. The job name must be an object, not a string.
C. The delay value should be a number, not a string.
D. The data parameter is missing.
Solution
Step 1: Check types of job options
delay expects a number in milliseconds, but here it is a string '1000'.
Step 2: Validate other parameters
attempts is valid, job name as string is correct, data is present.
Final Answer:
The delay value should be a number, not a string. -> Option C
Quick Check:
delay must be number, not string [OK]
Hint: Delay must be number type, not string [OK]
Common Mistakes:
Passing delay as string instead of number
Removing valid attempts option
Thinking job name must be object
5. You want to add a job that should run after 10 seconds, retry up to 4 times if it fails, and run before other jobs with default priority. Which job options object is correct?
hard
A. { delay: 10000, attempts: 4 }
B. { delay: 10000, attempts: 4, priority: 1 }
C. { attempts: 4, priority: 0 }
D. { delay: 10000, priority: 0 }
Solution
Step 1: Understand default priority
If priority is not set, jobs have default priority (usually 0 or normal). To run before others, priority must be lower number.
Step 2: Check options for delay and attempts
Delay 10000 ms (10 seconds) and attempts 4 are required. Priority is optional if default is acceptable.
Step 3: Analyze options
{ delay: 10000, attempts: 4, priority: 1 } sets priority to 1 (lower priority than default 0), so it runs after default priority jobs. { delay: 10000, attempts: 4 } omits priority, so default priority applies, running before jobs with priority 1.