Open BookOfGreg opened 6 years ago
Hi @BookOfGreg, I've found the same problem than you. Then, I came to this solution that I've added to my snakers initializer file (config/initializers/sneakers.rb) instead of modifying the sneaker tasks file as you did. Maybe it could help you.
# Preload all jobs defined for the application
Dir.glob(File.expand_path("app/jobs/*_job.rb", Rails.root)).each do |job_file|
require job_file
end
# Then create a list of queues names based on the defined jobs
queues = ApplicationJob.descendants.map(&:queue_name).uniq
# Finally, dynamically create a worker class for each queue name, very much
# as you do in #331, but including the Sneakers::Worker module again, to force
# Sneakers to add the new class to its classes array
queues.each do |queue_name|
Object.const_set("#{queue_name}_worker".classify,
Class.new(ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper) do
include Sneakers::Worker
from_queue queue_name
end)
end
Thx @leio10 , for everyone missing a queue for your mailers (based on ActionMailer) you have to include it to your queues:
queues = (["mailers"] | ApplicationJob.descendants.map(&:queue_name)).uniq
@leio10 and @forelabs: to clarify, if you have a mailers
queue, do you run WORKERS=MailersWorker rake sneakers:run
? That's how I interpret this but I wanted to make sure I understand :)
@wwahammy When I want to only run this worker then yes, while I'm developing i normally just ran rails sneakers:run
which will start all workers.
Try another adapter https://github.com/veeqo/advanced-sneakers-activejob
I wanted to link together this gem and this stale Rails/Rails issue about Sneakers not handling reading the specified Queue in it's adapter.
Could we update the docs [1, 2] with information on how to process a specific queue?
Perhaps as a solution you would accept a PR that enhances the Rake task with the queue's to process?