0
0
Ruby on Railsframework~10 mins

Job creation and queuing in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a basic Active Job class.

Ruby on Rails
class MyJob < ApplicationJob
  queue_as :[1]

  def perform(*args)
    # job code here
  end
end
Drag options to blanks, or click blank then click option'
Aurgent
Bmain
Cbackground
Ddefault
Attempts:
3 left
💡 Hint
Common Mistakes
Using a queue name that is not defined in the system
Forgetting to set a queue name
2fill in blank
medium

Complete the code to enqueue a job to run asynchronously.

Ruby on Rails
MyJob.[1](user_id)
Drag options to blanks, or click blank then click option'
Aperform_later
Bperform_now
Cenqueue
Drun_async
Attempts:
3 left
💡 Hint
Common Mistakes
Using perform_now which runs the job immediately
Using non-existent methods like run_async
3fill in blank
hard

Fix the error in the job class to correctly access the argument.

Ruby on Rails
class NotifyUserJob < ApplicationJob
  def perform([1])
    UserMailer.welcome_email([1]).deliver_now
  end
end
Drag options to blanks, or click blank then click option'
Aparams
Bargs
Cuser_id
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic name like args without unpacking
Using user when only the ID is passed
4fill in blank
hard

Fill both blanks to schedule a job to run 5 minutes from now.

Ruby on Rails
MyJob.[1](wait: [2].minutes).perform_later
Drag options to blanks, or click blank then click option'
Aset
Bperform_later
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using perform_later without set for scheduling
Using wrong wait time values
5fill in blank
hard

Fill all three blanks to create a job that retries 3 times with 10 seconds delay between attempts.

Ruby on Rails
class RetryJob < ApplicationJob
  [1] StandardError, wait: [2], attempts: [3]

  def perform
    # job code
  end
end
Drag options to blanks, or click blank then click option'
Aretry_on
B10.seconds
C3
Drescue_from
Attempts:
3 left
💡 Hint
Common Mistakes
Using rescue_from which handles exceptions differently
Not specifying wait time or attempts correctly