jondot / sneakers

A fast background processing framework for Ruby and RabbitMQ
https://github.com/jondot/sneakers
MIT License
2.25k stars 333 forks source link

Does not handle processing queues in ActiveJob #330

Open BookOfGreg opened 6 years ago

BookOfGreg commented 6 years ago

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?

leio10 commented 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
forelabs commented 5 years ago

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
wwahammy commented 4 years ago

@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 :)

forelabs commented 4 years ago

@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.

sharshenov commented 4 years ago

Try another adapter https://github.com/veeqo/advanced-sneakers-activejob