I had huge issues with starting sidekiq on Heroku after updating my gems and putting everything into production. The problem was that Sidekiq tried to connect to Redis on a local connection and port, instead of using the REDISTOGO variable. After spending a few hours, I managed to fix it: Answer below.
Remove everything from the if and below and run this:
heroku config:set REDIS_PROVIDER=REDISTOGO_URL
Sidekiq will automatically use it.
I looked up the correct, new connection that RedisToGo provides and then inserted it into the variables. Some posts here on SO claimed that this wasn't necessary, but it seems it is.
My sidekiq.rb file in the initializers now looks like this, everything works.
require 'sidekiq/web'
Sidekiq.configure_server do |config|
ActiveRecord::Base.configurations[Rails.env.to_s]['pool'] = 30
end
if Rails.env.production?
Sidekiq.configure_server do |config|
config.redis = { url: ENV["REDISTOGO_URL"]}
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV["REDISTOGO_URL"]}
end
end
Not an answer - but want to add to the SEO for this post so others can find this.
This is also the answer to an issue where heroku will throw the error:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
This issue has been unanswered on many SO questions (example), and everyone says the database isn't correctly configured, which is not necessarily the case.
I tried for hourrrrsss to figure out the issue, and this was the solution! Thank you so much - I wish I could upvote your answers more than once!!
Related
This is my first time using redis and the only reason I am is because I'm trying out autocomplete search tutorial. The tutorial works perfectly in development but I'm having trouble setting up redis for heroku.
I already followed these steps on the heroku docs for setting up redis but when I run heroku run rake db:seed I get Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
I'm not very familiar with heroku so if you guys need any more information let me know.
Edit
I've completed the initializer steps shown here and when I run heroku config:get REDISCLOUD_URL the result is exactly the same as the Redis Cloud URL under the config vars section of my Heroku settings.
Following the documentation, I then set up config/initializers/redis.rb like so:
if ENV["REDISCLOUD_URL"]
$redis = Redis.new(:url => ENV["REDISCLOUD_URL"])
end
Just to check, I tried substituting the actual URL for redis cloud inside the if block instead of just the REDISCLOUD_URL variable but that didn't work. My error message hasn't changed when I try to seed the heroku db.
It’s not enough to just create a $redis variable that points to the installed Redis server, you also need to tell Soulmate about it, otherwise it will default to localhost.
From the Soulmate README you should be able to do something like this in an initializer (instead of your current redis.rb initializer, which you won’t need unless you are using Redis somewhere else in your app):
if ENV["REDISCLOUD_URL"]
Soulmate.redis = ENV["REDISCLOUD_URL"]
end
Looking at the Soulmate source, an easier way may be to set the REDIS_URL environment variable to the Redis url, either instead of or as well as REDISCLOUD_URL, as it looks like Soulmate checks this before falling back to localhost.
Your code is trying to connect to a local Redis instance, instead the one from Redis Cloud - make sure you've completed the initializer step as detailed in order to resolve this.
I have a rails 4 application successfully running locally with cancan. But when I push it to Heroku, I get this error, each time the code tries to authorize anything
Uninitialized constant ApplicationController::Ability
Looking at the logs, it looks like its failing in this method, which I have in my application controller. Any idea what is going on?
def current_ability
#current_ability ||= Ability.new(current_user, load_service_provider_from_host)
end
This works fine on my local machine.
I managed to figure out what the issue is. The issue was, my ability class file was named Ability.rb. Note the upper case. When I changed it to lower case (ability.rb), just like all the other models, it worked fine. It still would be nice to know why this failed only on heroku and not locally.
My Heroku app is www.inflationtrends.com.
Usually, when I run "pg:info" in Git Bash to see how many connections there are, that number is zero.
Recently, I've seen a spike in traffic -- not much, only a little over 1,000 in the past 48 hours -- and when I ran "pg:info" this morning (around 11 a.m. Eastern time), the result shows that there are 4 or 5 open connections.
My app is run using the Ruby gem Sinatra. In the Sinatra file, I have the following code:
after do
DB.disconnect
end
The "after do" loop disconnects from the PostgreSQL database after a page is loaded.
The variable "DB" has the connection info for my PostgreSQL database (username, password, host, port number, SSL mode requirement):
DB = Sequel.postgres(
db_name,
:user=>user,
:password=>password,
:host=>host,
:port=>port,
:sslmode=>sslmode
)
Is there some reason that there are open connections? Are there ways to close these connections? Are there more efficient ways to handle this situation?
An alternate way to check the number of open connections on Heroku is to type this into your console/terminal and replace "myapp" with your app's name:
heroku pg:info -a myapp
Have you considered that perhaps your site is getting traffic? When people visit your site and use your application connections will be opened.
Try adding some tracking code (such as Google Analytics) to your web pages, then check if the number of recorded visitors matches the number of open connections.
It is also possible that the database has connections opened by various maintenance tasks, such as backing up.
I grabbed the following toolbelt add-on which worked perfectly.
https://github.com/heroku/heroku-pg-extras#usage
heroku pg:killall --app xyz
I've been using the connection option :connecttimeoutms when setting up MongoDB connections using the mongodb ruby gem. Like so:
connection = Connection.from_uri(uri, :connecttimeoutms => connect_timeout)
Now getting warnings that
connecttimeoutms is not a valid option for Mongo::Connection
since a recent bundle update.
Has this disappeared? Does anyone know what I should replace it with?
#sumskyi is absolutely right of course
After such investigation it seems it is now :connect_timeout and is measured in seconds
Thanks
I am troubleshooting a ruby script that queries a database, creates a csv, and sftps it to another server. The server the script is on is a rhel box, running ruby 1.87 I believe.
Here's the code that does the sftping:
Net::SFTP.start(sftp_site, sftp_user, :password => sftp_pswd) do |sftp|
sftp.upload!(local_filepath,sftp_dir+filename)
end
When executing the script, there is a curious message before it bombs out:
Password Reset
Your password has expired. You are required to change your password to proceed.
This script works on another server, but not this one. A user can sftp from the prompt on this machine. SELinux has been turned off, as it may have had some interference.
Anyway, point being, does anyone have any ideas?
It appeared to be a gem issue (though someone in networking may have worked some magic I am unaware of). The production server had older versions of the net/ssh and net/sftp gems. It had version 1.1.1 and version 1.1.2, respectively, and upgrading those gems to a later version fixed the issue.
Thanks for everyone who offered suggestions!
I would compare the sshd daemon settings (sshd_config), as there's likely an issue in the server that's not working. Perhaps interactive-keyboard authentication is turned on or something like that?