Performance: Job priorities and queues
This affects how background jobs are processed, impacting response time and server load distribution.
class HardJob < ApplicationJob queue_as :hard def perform(*args) # long running task end end class SoftJob < ApplicationJob queue_as :soft def perform(*args) # quick task end end # Configure workers to prioritize 'soft' queue over 'hard' queue
class HardJob < ApplicationJob queue_as :default def perform(*args) # long running task end end class SoftJob < ApplicationJob queue_as :default def perform(*args) # quick task end end
| Pattern | Queue Usage | Job Processing Delay | Server Load Distribution | Verdict |
|---|---|---|---|---|
| Single default queue | One queue for all jobs | High delay for important jobs | Uneven, long tasks block others | [X] Bad |
| Multiple prioritized queues | Separate queues by priority | Low delay for high priority jobs | Balanced load, faster critical job processing | [OK] Good |
queue_as to set the queue name inside job classes.queue_as :default is the correct way to assign the queue.class EmailJob < ApplicationJob
queue_as :mailers
def perform(user_id)
# send email
end
endqueue_as :mailers, so it uses the 'mailers' queue.class CleanupJob < ApplicationJob
queue_as = :low_priority
def perform
# cleanup code
end
endqueue_as :low_priority without '='.class UrgentJob < ApplicationJob
queue_as :urgent
def perform
# urgent task
end
end
class NormalJob < ApplicationJob
queue_as :normal
def perform
# normal task
end
endPass the test and this pattern moves unknown