Home > OS >  Sidekiq not running enqueued jobs (Rails 7 Redis Sidekiq Docker)
Sidekiq not running enqueued jobs (Rails 7 Redis Sidekiq Docker)

Time:11-04

As the title says, i have 3 containers running in docker, 1 for rails, 1 for a postgres db and 1 for redis. I'm able to enqueue jobs doing Job.perform_async but for some reason my jobs stay on the enqueued indefinitely. I checked and my Redis container is up and running.

My Job:

class HardJob
  include Sidekiq::Job

  def perform(*args)
    puts 'HardJob'
  end
end

The initializer for sidekiq:

Sidekiq.configure_server do |config|
    config.redis = { url: (ENV["REDIS_URL"] || 'redis://localhost:6379') }
end 
  
Sidekiq.configure_client do |config| 
    config.redis = { url: (ENV["REDIS_URL"] || 'redis://localhost:6379') }
end

My docker-compose:

version: '3.0'

services:
  web:
    build: .
    entrypoint: >
      bash -c "
      rm -f tmp/pids/server.pid
      && bundle exec rails s -b 0.0.0.0 -p 3000"
    ports:
      - 3000:3000
    volumes:
      - .:/src/myapp
    depends_on:
      - db
      - redis
    links:
      - "db:db"
    environment:
      REDIS_URL: 'redis://redis:6379'
  db:
    image: postgres:11
    environment:
      POSTGRES_PASSWORD: 'postgres'
    volumes:
      - db_data:/var/lib/postgresql/data
    ports:
      - 5432:5432
  redis:
    image: "redis"
volumes:
  db_data:
  redis:
    driver: local

And i also set config.active_job.queue_adapter = :sidekiq in my 3 environments. enter image description here

Any hint of what could be happening here? Thanks in advance

Update

Seems that running sidekiq -q default in my rails terminal worked. How can i configure Docker to always run sidekiq?

CodePudding user response:

Sidekiq is looking for the wrong queue name for some reason. Try adding this to your config/sidekiq.yml file.

:queues:
  - default

CodePudding user response:

Sidekiq is process on it own and needs to be started on it own, just like the web server process. Add something like the following to docker-compose:

sidekiq:
  depends_on:
    - 'db'
    - 'redis'
  build: .
  command: bundle exec sidekiq
  volumes:
  - .:/src/myapp
  environment:
    - REDIS_URL_SIDEKIQ=redis://redis:6379/1

Or – when you are able to use the latest version of Sidekiq (>= 7.0) – you might want try out the new Sidekiq embedded mode that runs Sidekiq in together with your puma webserver.

  • Related