Search code examples
ruby-on-railssidekiqrails-console

What's the difference between starting sidekiq inside rails directory and within an existing rails process (like console) using fork


$ rails console

[1] pry(main)> fork { exec "bundle exec sidekiq -c 3 crawling_jobs -t 1 -L log/sidekiq.log" }
=> 7306

bundler: failed to load command: sidekiq (/Users/raducroitoru/.rbenv/versions/2.5.3/bin/sidekiq)
LoadError: cannot load such file -- selenium-webdriver

Same command works within project directory.

For me it appears to be something like bin PATH issue, but I can't find any topics in regards to this. Appreciate any help.

Ruby: 2.5.3, Rails: 4.2.11.1, Sidekiq: 5.2.7 (ent: 1.8.1)


Solution

  • Essentially the forked process most likely doesn't inherit the same environment as your running console, so bundler wont load the correct gems (and hence it can't find selenium-webdriver) - you might fix it by adding a rails env var to the command e.g.

    fork { exec "RAILS_ENV=#{Rails.env} bundle exec sidekiq -c 3 crawling_jobs -t 1 -L log/sidekiq.log" 
    

    I said "might" because your console env (Rails.env) may also not have the gem group for selenium-webdriver.

    Although your question relates to firing this up from the console, is there a reason you need to do this from an existing rails process and not from the shell ?