0
0
Ruby on Railsframework~20 mins

Active Job framework in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Active Job Mastery
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 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')
AThe job is added to the queue and will run asynchronously later.
BThe job runs immediately and blocks the current thread.
CThe job is discarded and never runs.
DThe job raises an error because perform_later is undefined.
Attempts:
2 left
💡 Hint
Think about how Active Job handles background processing.
📝 Syntax
intermediate
2: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?
A
class WelcomeJob &lt; ApplicationJob
  def perform(user_id)
    UserMailer.welcome(user_id).deliver_now
  end
end
B
class WelcomeJob &lt; ApplicationJob
  def perform
    UserMailer.welcome(user_id).deliver_now
  end
end
C
class WelcomeJob &lt; ApplicationJob
  def perform(user)
    UserMailer.welcome(user.id).deliver_now
  end
end
D
class WelcomeJob &lt; ApplicationJob
  def perform(user_id)
    UserMailer.welcome(user).deliver_now
  end
end
Attempts:
2 left
💡 Hint
The perform method must accept the arguments passed when enqueuing.
🔧 Debug
advanced
2: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
ABecause ApplicationJob does not allow calling methods inside perform.
BBecause perform must be a class method, not instance method.
CBecause user argument is missing when calling perform_later.
DBecause send_email is not defined in the job or included modules.
Attempts:
2 left
💡 Hint
Check if the method send_email is defined anywhere accessible.
state_output
advanced
2: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)
ARuntimeError because perform_now is undefined.
BCount is: 5
CNo output because perform_now does not print.
DCount is: 0
Attempts:
2 left
💡 Hint
perform_now runs the job immediately in the current thread.
🧠 Conceptual
expert
2: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?
A:delayed_job
B:resque
C:inline
D:sidekiq
Attempts:
2 left
💡 Hint
This adapter does not queue jobs but runs them right away.