Dave
Dave

Reputation: 19090

How do I view my sidekiq console output locally using the default queue?

I'm using Rails 5. I would like to create a sidekiq process running locally using the default queue. My worker class looks roughly like the below ...

module Accounting::Workers
  class FileGenerationWorker
    include Sidekiq::Worker

    def perform
      print "starting work ...\n"
      ...

I have set up my config/sidekiq.yml file like so, in hopes of running the worker daily at a specific time (11:05 am) ...

:concurrency: 20
:queues:
  - default
    ...
:schedule:
  Accounting::Workers::FileGenerationWorker:
    cron: "0 5 11 * *"
    queue: default

However, when I start my rails server ("rails s"), I don't see my print statement output to the console or any of the work performed, which tells me my worker isn't running. What else am I missing in order to get this worker scheduled properly locally?

Upvotes: 3

Views: 3443

Answers (1)

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38922

Run the workers with

bundle exec sidekiq

You may need to provide the path to the worker module. For example,

bundle exec sidekiq -r ./worker.rb

Sidekiq by itself doesn't support a :schedule: map entry in the Sidekiq configuration file.

Periodic job functionality is provided in extensions such as sidekiq-scheduler.

You need to use classes declared in the extended Sidekiq module provided in sidekiq-scheduler. For example,

./worker.rb

require 'sidekiq-scheduler'

require './app/workers/accounting'

Sidekiq.configure_client do |config|
 config.redis = {db: 1}
end

Sidekiq.configure_server do |config|
 config.redis = {db: 1}
end

./app/workers/accounting.rb

module Accounting
   # ...
end

module Accounting::Workers
  class FileGenerationWorker
    include Sidekiq::Worker

    def perform
      puts "starting work ...\n"
    end
  end
end

Upvotes: 1

Related Questions