Performance: Scheduled jobs
Scheduled jobs affect background processing speed and server resource usage, indirectly impacting user experience by offloading work from request cycles.
class CleanupJob < ApplicationJob queue_as :default def perform(batch_size: 100) User.find_in_batches(batch_size: batch_size) do |users| users.each { |user| user.posts.destroy_all } end end end # Scheduled with cron and uses batch processing with Sidekiq concurrency
class CleanupJob < ApplicationJob queue_as :default def perform User.all.each do |user| user.posts.destroy_all end end end # Scheduled with cron to run every hour synchronously
| Pattern | Server Load | Blocking Time | Resource Usage | Verdict |
|---|---|---|---|---|
| Synchronous large batch job | High | Long blocking | High memory spikes | [X] Bad |
| Asynchronous batched job | Moderate | Short blocking | Controlled memory use | [OK] Good |
MyJob.perform_now is called?class MyJob < ApplicationJob
def perform
puts 'Job executed'
end
endclass CleanupJob < ApplicationJob
def perform
User.delete_all
end
end
# Schedule in config/schedule.rb
every 1.day do
runner 'CleanupJob.perform_later'
endwhenever gem?class ArchiveJob < ApplicationJob
def perform
Record.archive_old
end
end
# config/schedule.rb
? Which snippet correctly schedules the job?Pass the test and this pattern moves unknown