Challenge - 5 Problems
Active Job Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when a job is enqueued with perform_later?
Consider a Rails Active Job class with a
perform method. What is the behavior when you call MyJob.perform_later(args)?Ruby on Rails
class MyJob < ApplicationJob def perform(name) puts "Hello, #{name}!" end end MyJob.perform_later('Alice')
Attempts:
2 left
💡 Hint
Think about how Active Job handles background processing.
✗ Incorrect
Calling perform_later adds the job to the queue to be run asynchronously by a background worker.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a job with arguments?
You want to create a job that accepts a user ID and sends a welcome email. Which job class definition is correct?
Attempts:
2 left
💡 Hint
The perform method must accept the arguments passed when enqueuing.
✗ Incorrect
The perform method should accept the exact arguments passed to perform_later. Option A correctly accepts user_id and uses it.
🔧 Debug
advanced2:00remaining
Why does this job raise a NoMethodError?
Given this job code, why does it raise
NoMethodError: undefined method 'send_email'?Ruby on Rails
class EmailJob < ApplicationJob def perform(user) send_email(user) end end
Attempts:
2 left
💡 Hint
Check if the method send_email is defined anywhere accessible.
✗ Incorrect
The method send_email is not defined in the job class or any included module, so calling it causes a NoMethodError.
❓ state_output
advanced2:00remaining
What is the output after running this job with perform_now?
Consider this job and the code that runs it. What will be printed?
Ruby on Rails
class CountJob < ApplicationJob def perform(count) puts "Count is: #{count}" end end CountJob.perform_now(5)
Attempts:
2 left
💡 Hint
perform_now runs the job immediately in the current thread.
✗ Incorrect
Calling perform_now runs the job immediately, so the puts statement outputs the count value.
🧠 Conceptual
expert2:00remaining
Which backend adapter supports running jobs inline for testing?
In Rails Active Job, which adapter runs jobs immediately in the same process, useful for testing?
Attempts:
2 left
💡 Hint
This adapter does not queue jobs but runs them right away.
✗ Incorrect
The :inline adapter runs jobs immediately in the same process, which is helpful for tests to avoid asynchronous behavior.