Dave
Dave

Reputation: 19150

Why isn't my Rails worker executing?

I'm using Rails 5.0.1 on mac OS X. I just installed redis via homebrew, and have this in my Gemfile

gem 'sidekiq'

and I have this file, app/workers/run_crawlers_worker.rb, ...

class MyWorker

  include Sidekiq::Worker

  def perform()
    puts "about to fire up service ..."
    svc = MyService.new
    svc.do_tasks
    puts "done invoking call"
  end

end

At a place in my web application, I have

    MyWorker.perform_async()

although I'm confident the above is getting called, I don't see any of my "perform" method in my worker called (I don't see any of hte puts output and I don't see the results of the "do_tasks" method getting executed in my db). Is there something additioanl I need to configure to get my method invoked?

Upvotes: 2

Views: 1227

Answers (2)

Paritosh Piplewar
Paritosh Piplewar

Reputation: 8122

Is there something additioanl I need to configure to get my method invoked?

You need sidekiq process running in background which will be responsible to run the jobs you enqueue.

Is there any way to get "bundle exec sidekiq" to automatically run when I fire up my Rails server?

Put into foreman. It is pretty easy. I am assuming basic configuration, this is all you need to do

  1. Install foreman gem. (put into bundle and do bundle install)
  2. you have to create file named Procfile in rails root.
  3. Assuming basic configuration, this is what Procfile suppose to contain

    web: bundle exec rails server
    worker: bundle exec sidekiq
    
  4. then to execute both command spontaneously, just execute foreman start

Upvotes: 0

vpetkar
vpetkar

Reputation: 67

You likely don't have sidekiq running, I would recommend looking into Foreman which can be configured to run all of your expected processes (Rails server, workers, Redis, etc.) at once.

Upvotes: 1

Related Questions