Sidekiq in development environment - ruby-on-rails

I have a longstanding project that is using sidekiq with redis and a problem that has started I believe only since upgrading to sidekiq 3+.
The problem is that I can't run my rails (4.1.4) app in development without first starting a redis server. I get the same error starting the rails server as I get when I try to run bundle exec sidekiq without first starting redis. Running my rails app without redis running was never a problem before, even though sidekiq was setup the same way.
Can someone suggest a way around having to start a redis server even when I don't intend to run sidekiq?
Here is the backtrace:
/Users/mark/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:309:in
rescue in establish_connection': Error connecting to Redis on
127.0.0.1:6379 (ECONNREFUSED) (Redis::CannotConnectError) from /Users/mark/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:304:in
establish_connection' from
/Users/mark/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:85:in
block in connect' from
/Users/mark/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:266:in
with_reconnect' from
/Users/mark/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:84:in
connect' from
/Users/mark/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:326:in
ensure_connected' from
/Users/mark/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:197:in
block in process' from
/Users/mark/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:279:in
logging' from

I think this problem is related to https://github.com/tobiassvn/sidetiq/issues/103.
Unfortunately, the fix has not been pulled into the main repo yet. You can try using the fixed fork in your Gemfile to see if it fixes the problem:
gem 'sidetiq', github: 'nkondratyev/sidetiq', branch: 'fix_working_with_prefork_servers'

Related

foreman start doesn't seem to bind puma socket in development

I'm working a Rails application ran into some problems with a 502 error when I tried to go to our staging site. This thread had the answer I needed by adding to puma.rb:
application_path = '/home/deploy/hotel-automata/shared'
bind "unix://#{application_path}/sockets/puma.socket"
I was also able to start the server in development by running foreman start -p 3000. The question I have is how does this not throw an error? The application_path I have definitely doesn't exist in my local computer and running bundle exec puma or bundle exec rails server threw an error on file not found. Is this something that's specific to foreman or am I missing something? I looked around for a while but couldn't find anything related to this.
Also, is this the best way to do this? I feel that using an exact path might not be the best way here but I'm not sure what else I should do. Any suggestions on this point would be much appreciated too.
Also, here's my Procfile:
web: bundle exec rails server
redis: redis-server
sidekiq: bundle exec sidekiq

The localhost page isn’t working ruby rails puma osx

I have been working on a rails app for months and then, all of a sudden the pumas server does not work on my laptop. I've tried different older branches (in case I changed something) I've uninstalled and reinstalled ruby. Nope. It DOES work if I do a fresh pull and load it on my desktop, so it seems to be something on my laptop? I am really lost.
Here's what I've done already:
Restarted the computer
reinstalled ruby
Tried puma
Tried rails s
Tried different branches to see if something I did yesterday somehow broke it
reinstalled gems
The error is:
The localhost page isn’t working
localhost didn’t send any data.
However, right before it was running this error, it ran a Request time out error, if that matters.
What I really don't understand is why it's only happening on one computer.
I am running Ruby 2.3.0 and rails 4.2.6
UPDATE
It DOES running rails server and not puma.
The problem is, I'm using foreman to start sidekiq with my server, and that's how I debug sidekiq queues. Strangely, sidekiq still works, but I can't access the localhost page.
This is my procfile:
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -c 2 -q default -q mailers
Again, I haven't changed anything with puma and rails s works fine.

Running Sidekiq in Rails app using AWS Elasticache

I am trying to configure Sidekiq in a Rails 4.1.4 application that connects to an AWS Elasticache Node running Redis.
I set up my Redis server, and followed the directions in this AWS Guide:
http://docs.aws.amazon.com/opsworks/latest/userguide/other-services-redis-cluster.html
And my Redis server was running properly and my app server could connect properly.
I followed these directions to set up Sidekiq to run on the external worker:
https://github.com/mperham/sidekiq/wiki/Advanced-Options
Whenever I visited my app server at the /sidekiq url to view the Sidekiq panel, I kept getting the error on screen saying "Internal Server Error".
My Unicorn error logs do not contain any relevant information, so I am not sure how to get this working. AWS support did not have any answers either.
Any information would be greatly appreciated. Thanks!
This problem is normally seen when assets are not compiled or are not configured to be served from your environment. Start your app/sidekiq in production mode (or whatever environment this is referring to) after changing the production config to point to your local resources (redis+db) and see if the pages are able to load then.
RAILS_ENV=production bundle exec unicorn
RAILS_ENV=production bundle exec sidekiq -c config/sidekiq.yml

Rails server hangs when started with foreman

Here's what my Procfile looks like:
web: bundle exec rails server thin -p $PORT -e $RACK_ENV
worker: bundle exec rake jobs:work
I intend to add a worker process because I wish to run some background jobs. I'm following these instructions
This is what I noticed:
No problems encountered if the worker is started separately.
When I keep the second line in the Procfile and don't not change anything else, the rails server serves a couple of requests and hangs after that
As mentioned here , I've added STDOUT.sync = true to config/environments/development.rb and verified the same in the rails console. Did not work.
Tailed log/development.log and compared it against the stuff that foreman outputted to the shell and noticed that both matched for a couple of requests and then foreman stopped printing out stuff to the shell - the next request would then hang
I updated foreman using foreman.pkg as mentioned here and verified the same with [6]
It was mentioned here that this might be caused due to a stray debug statement. I'm not using the debugger and I do not have the pry gem or the ruby-debug gem in my Gemfile.lock
I believe the symptoms are similar to this related unanswered question
Please help!
[6]:
which foreman
/usr/bin/foreman
ls -lah /usr/bin/foreman # checked the updated date
Tracked and resolved here:
https://github.com/ddollar/foreman/issues/244
TL;DR: Install the gem, don't use foreman.pkg
I'll add than if you're using Heroku, the foreman version included with the heroku toolbelt has the same issue.
Use the one you can get with gem install foreman instead.

Delayed Job fails on heroku but runs locally

I have a Delayed Job that processes a bunch of S3 objects with aws/s3. It works locally via "rake jobs:work" but it fails on Heroku with the following error:
"{Job failed to load: uninitialized constant Net::HTTP::ConnectionPool..."
I am also able to fire up the Heroku console via "heroku run console" and run the job's method with out issue. The ConnectionPool comes from aws so I have attempted to force require 'aws/s3' but it didn't help. Any ideas?
Gems:
aws-sdk (1.5.6)
rails (3.1.0)
delayed_job (3.0.3)
It turned out that I was reusing a s3 connection from a module. The module would return an existing connection if it existed, and it created a new one if it did not. I'm not sure why it worked in my local DJ and not on the Heroku Worker as I do not think there should have been an existing connection in either environment AND the job was kicked off with a rake task in both cases, as was the worker. Anyway, after creating a new S3 connection via AWS::S3.new within the job, the problem was solved.
Hope this helps someone.

Resources