0
0
Ruby on Railsframework~20 mins

Job creation and queuing in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Job Queue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a job is enqueued with perform_later?

Consider a Rails Active Job class SendEmailJob. When you call SendEmailJob.perform_later(user_id), what is the immediate behavior?

Ruby on Rails
class SendEmailJob < ApplicationJob
  queue_as :default

  def perform(user_id)
    # send email logic
  end
end

SendEmailJob.perform_later(42)
AThe job runs immediately and blocks the current thread until done.
BThe job runs synchronously but in a new thread.
CThe job is discarded because perform_later is not a valid method.
DThe job is added to the queue and will run asynchronously later.
Attempts:
2 left
💡 Hint

Think about how perform_later differs from perform_now.

📝 Syntax
intermediate
1:30remaining
Identify the correct syntax to set a custom queue in a job class

Which of the following correctly sets the queue name to :mailers in a Rails Active Job class?

Ruby on Rails
class NotificationJob < ApplicationJob
  # set queue here
  queue_as :mailers

  def perform
    # job code
  end
end
Aqueue_as :mailers
Bself.queue = :mailers
Cset_queue :mailers
Dqueue_name :mailers
Attempts:
2 left
💡 Hint

Look for the official method to assign queue names in Active Job.

🔧 Debug
advanced
2:30remaining
Why does this job never run after enqueuing?

Given the following job and code, why does the job never execute?

Ruby on Rails
class CleanupJob < ApplicationJob
  queue_as :default

  def perform
    puts "Cleaning up..."
  end
end

CleanupJob.perform_later
AThe job is enqueued but no queue adapter is configured to process jobs.
BThe job class is missing the <code>perform</code> method.
CThe <code>perform_later</code> method requires an argument.
DThe job runs immediately and finishes before output can be seen.
Attempts:
2 left
💡 Hint

Check if the background job processor is running or configured.

state_output
advanced
1:30remaining
What is the output after running this job with arguments?

What will be printed when the following job is enqueued and performed?

Ruby on Rails
class GreetJob < ApplicationJob
  def perform(name)
    puts "Hello, #{name}!"
  end
end

GreetJob.perform_now("Alice")
AError: wrong number of arguments
BHello, Alice!
CHello, !
DNo output
Attempts:
2 left
💡 Hint

Consider how perform_now works with arguments.

🧠 Conceptual
expert
3:00remaining
Which queue adapter supports job retries natively in Rails?

Among the default Rails queue adapters, which one supports automatic job retries without extra configuration?

AInline adapter
BAsync adapter
CSidekiq adapter
DTest adapter
Attempts:
2 left
💡 Hint

Think about which adapter is designed for production background processing with retry features.