How to run rake sneakers:run

1.6k views Asked by At

I am trying Rabbitmq and sneakers for the first time. And I am facing some issues when i try to run my workers. I have added the following line in application.rb

    config.active_job.queue_adapter = :sneakers

And when i run rake --tasks, sneakers is not listed

This is my sneakers.rb file

     require 'sneakers'
     Sneakers.configure  connection: Bunny.new(
      addresses: 'localhost:5672',
      username: 'guest',
      password: 'guest',
      vhost: '/',
      logger: Rails.logger
     ),
     exchange: 'sneakers',
     exchange_type: :direct,
     workers: 1,
     env: ENV['RAILS_ENV'], 
     durable: true,
     ack: true,
     heartbeat: 30
    Sneakers.logger = Rails.logger
    Sneakers.logger.level = Logger::WARN

Rails version - 4.2.4. Ruby version - 2.3.3. Sneakers version - 2.11.0

I am stuck here. Any solutions or any docs for reference will also be helpful.

1

There are 1 answers

0
Nick M On BEST ANSWER

You're supposed to add require 'sneakers/tasks' to your Rakefile, once you do that rake -T will show the sneakers tasks. To start workers you can:

rake sneakers:run       # Start work (set $WORKERS=Klass1,Klass2)

Also I ran into a strange issue: the sneakers rake task would sometimes error out with "no workers found", not sure whether its a Rails autoloading issue or not, but the solution is to create another rake task of your own where you instantiate each of your worker classes and then invoke the sneakers:run task:

# lib/tasks/amqp.rake
desc "Run all of your sneakers tasks"
task :amqp => :environment do
  MyRandomWorker
  MyOtherSneakersWorker
  Rake::Task["sneakers:run"].invoke
end