ive been trying to get resque to work with heroku. i can successfully get it to work in development mode, however when i try pushing to heroku i get
Errno::ECONNREFUSED (Connection refused - Unable to connect to Redis on 127.0.0.1:6379):
i then read and followed http://blog.redistogo.com/2010/07/26/resque-with-redis-to-go/
i put the configurations listed in the site but got the following error
SocketError (getaddrinfo: nodename nor servname provided, or not known):
i put in my initializers/resque.rb
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }
ENV["redis://redistogo:11111111111111111#lab.redistogo.com:9254/"] ||= "redis://heroku_username:heroku_password#host:9254/"
uri = URI.parse(ENV["redis://redistogo:1111111111111111#lab.redistogo.com:9254/"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
however it throws the error mentioned above. on my dev mode now, i get the error as well.
i tried using my heroku username (im using the add on from heroku), putting my password to heroku, and changing the port to 9254. however i keep getting the socket error now. what am i doing wrong?
help would be much appreciated. thank you
UPDATE.
#kevin
i tried
uri = URI.parse(ENV["my_url_string"] || "redis://localhost:9254/" )
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
in a initializer/redis.rb as well but i get the following error
Errno::ECONNREFUSED (Connection refused - Unable to connect to Redis on 127.0.0.1:6379):
are the numbers in the error, ie 127.0.0.1:6379 significant? ive checked my redis gui app and also from heroku config that my port number is 9254
REDISTOGO_URL => redis://redistogo:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx#lab.redistogo.com:9254/
did you have any other configuration settings? thanks for helping!
FINAL UPDATE.
i fixed it. i can't believe it! my complete solution is
uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Resque.redis = REDIS
verbatim. it works without explicitly setting the url because i guess heroku tries to set it up for me already
For my setup I have /config/initializers/redis.rb with these lines:
uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/" )
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
My REDISTOGO_URL is defined in my heroku configuration. You should be able to validate that by typing:
heroku config --app my_app
You'll see in the output the value for REDISTOGO_URL
You should copy your REDISTOGO_URL directly from Redis To Go. You find it in by going to the instance in heroku and clicking on Add Ons -> Redis To Go.
Here are a couple pointers:
Verify you have your REDIS_TO_GO URL in your heroku config from the command line like I've demonstrated above.
Verify the REDIS_TO_GO URL is identical to the one assigned to that instance in the Add Ons -> Redis To Go config.
i fixed it. i can't believe it! my complete solution is
uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
Resque.redis = REDIS
verbatim. it works without explicitly setting the url because i guess heroku tries to set it up for me already
I got the same thing, so, basically Sidekiq was not grabbing the REDISCLOUD_URL from vars, it was grabbing REDIS_PROVIDER.
heroku config:set REDIS_PROVIDER=REDISCLOUD_URL
It worked like a charm.
Related
I am trying to send an email to a user upon sign up in my web app, which is built with Rails in the back end and React-Redux on the front end. I used a gem called letter_opener when testing on a local server, and everything seemed to work fine. When I tried it live on Heroku, I got back a 500 error, and I'm not sure what is wrong.
I tried reading the ActionMailer docs, but it didn't seem to mention any issue like this.
The method in the UserMailer:
def welcome_email(user)
#user = user
mail(to: #user.email, subject: "Welcome")
end
Relevant code in UsersController:
def create
# ...
email = UserMailer.welcome_email(#user)
email.deliver_now # This line throws the error
# ...
end
The error from the Heroku logs:
Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):
I expected to the email to be delivered, or at least to have a more informative error message. I am not sure why Rails is looking at localhost's port 25.
I am not sure why Rails is looking at localhost's port 25.
ActionMailer defaults to localhost:25, and you probably only changed your development configuration.
Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25)
Heroku doesn't provide an SMTP server, and there certainly won't be one on localhost. Use an email addon or some other third-party mail service of your choice.
You'll probably have to modify config/environments/production.rb to use whatever mail service you choose.
Chris is right, Heroku doesn't provide an SMTP server and you've to use an Addon. I'll further add on how you can proceed with using sendgrid addon which is free upto much extent.
First, goto your Heroku app -> Enable sendgrid addon. Then you'll be given sendgrid credentials. Keep them safe.
In your config/environments/production.rb add:
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: "your-domain.com", protocol: 'https' }
Then in your config/environment.rb file add:
...
# Initialize the Rails application.
Rails.application.initialize!
# Add sendgrid support
if Rails.env.production?
ActionMailer::Base.smtp_settings = {
:user_name => "sendgrid_username",
:password => "sendgrid_password",
:domain => "your-domain.com",
:address => "sendgrid_hostname",
:port => 3000, # sendgrid_port
:authentication => :plain,
:enable_starttls_auto => true
}
end
Change the credentials above as required. Also consider using ENV variables for above credentials.
I am quite new to redis. This rails application has a redis.rb file in config/initializers
uri = URI.parse(ENV["REDIS_URL"])
$redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
The redis url is on heroku config.
I can't just replace REDIS_URL with the REDIS_URL from heroku config.
I am getting a URI parse error
bad URI(is not URI?): (URI::InvalidURIError)
my question is where should I place the redis url ? where is it searching the env variable from?
I'm guessing you're getting this when doing rake. The problem is that when rake-ing, your environment variables aren't set, which leads to this error (info at https://devcenter.heroku.com/articles/rails-asset-pipeline). To overcome, use a conditional intializer instead, e.g.:
if ENV["REDISCLOUD_URL"]
uri = URI.parse(ENV["REDISCLOUD_URL"])
$redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
end
P.S. alternatively, use this but note that according to Heroku:
Using this labs feature is considered counter to Heroku best practices.
This labs feature can make your builds less deterministic and require
re-deploys after making config changes. Ideally your app should be able to
build without config.
I am attempting to setup Redis To Go on my Rails 4 app. I want to be able to deploy it to Heroku as well.
So far, this is what I've done:
Through the dashboard.heroku site, I used the one click install for the Nano version of Redis To Go to install the addon to my app.
I added gem 'redis' to my gemfile.
In config/environments/development.rb I added this line:
ENV["REDISTOGO_URL"] = 'redis://redistogo:b9fc604b1c86a1f6c232ce1dd16cd989#albacore.redistogo.com:10280/'
Then, I created a config/initializers/redis.rb file which looks like this:
uri = URI.parse(ENV["redis://redistogo:b9fc604b1c86a1f6d872ce1dd16cd989#albacore.redistogo.com:10280/"] || "redis://localhost:6379/")
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
When running a Redis command in my console now, I get this error:
Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)
What am I doing wrong here, and what do I need to do to ensure that I can test in development and deploy to Heroku without any issues?
ENV["REDISTOGO_URL"] should be in the environment on Heroku. I'd remove it from config/environments/development.rb altogether and change the redis.rb initializer to:
uri = URI.parse(ENV.fetch("REDISTOGO_URL", "redis://localhost:6379/"))
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
As long as that ENV var isn't set in development, it'll fall back to the local redis installation.
To update brandonhilkert's answer for Rails 4:
uri = ENV["REDISTOGO_URL"] || "redis://localhost:6379/"
REDIS = Redis.new(:url => uri)
Also, you might want to use Redis.current instead of setting a REDIS variable (see here).
For Rails 4 I did the following
In the console:
heroku addons:create redistogo
heroku config:set REDIS_PROVIDER=REDISTOGO_URL
In my Procfile I added:
worker: bundle exec sidekiq
In my 'gemfile.rb' I added:
gem 'redis'
I added the following file, config/initializers/redis.rb:
uri = ENV["REDISTOGO_URL"] || "redis://localhost:6379/"
REDIS = Redis.new(:url => uri)
I have my Sendgrid password set in an external file (config/application.yml) which I set up with the Figaro gem. This works fine on my local machine, but on my server I am getting an error that no password has been set:
ArgumentError (SMTP-AUTH requested but missing secret phrase)
When I change the Sendgrid config to just the plaintext password it works fine, so I assume that Rails isn't recognising the environment variable. The weird thing is that when I go into rails console production and execute puts ENV["SENDGRID_PASSWORD"] it works fine.
Any ideas?
Here's my Sendgrid config:
config.action_mailer.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587,
:user_name => "chrislawrence",
:password => ENV['SENDGRID_PASSWORD'],
:domain => "lakecinema.net.au",
:authentication => :plain,
:enable_starttls_auto => true
}
I had the same problem and couldn't figure out why Rails thought I wasn't giving it a password. Turns out I was defining config.action_mailer.smtp_settings in one file, and then adding key-value-combos to it in another file. The problem is that I was using merge instead of merge! so my password was never making it into smtp_settings but instead into a temporary hash.
From this experience I learnt that the error message you're getting is ActionMailer's way of saying "Where's the password?"
So my guess is that your issue is the inverse of Environment variable in Rails console and Pow, where an environment variable is working on the Rails server but not in Rails Console. Try executing:
$ echo "$SENDGRID_PASSWORD"
and see what you get. I have a feeling the Env variable is not set but that instead it's just a local variable in Rails Console.
It should be :authentication => 'plain'
I am using Sunspot rails(1.1.0). Everything works when I run my Rails
application and the Solr server on the same machine. When I run Solr
server on a different machine, I get the following error:
Errno::ECONNREFUSED: Connection refused - Connection refused
from /opt/tibco/jruby-1.4.0RC1/lib/ruby/1.8/net/http.rb:560:in `initialize'
from /opt/tibco/jruby-1.4.0RC1/lib/ruby/1.8/net/http.rb:560:in `new'
from /opt/tibco/jruby-1.4.0RC1/lib/ruby/1.8/net/http.rb:560:in `open'
After debugging through Sunspot code, I realized that the Solr::Client is connecting to localhost rather than the remote host configured in sunspot.yml. My sunspot.yml file is as follows:
production:
solr:
hostname: kingkong
port: 8983
log_level: WARNING
The build_session method(sunspot_rails-1.1.0/lib/rails.rb:line 24) tries to establish a slave session. The slave_config method ignores the configuration provided in sunspot.yml file. Here is the slave_config method:
def slave_config(sunspot_rails_configuration)
config = Sunspot::Configuration.build
config.solr.url = URI::HTTP.build(
:host => configuration.hostname,
:port => configuration.port,
:path => configuration.path
).to_s
config
end
Is this the intended behavior? Also, has anybody successfully connected to Solr running remotely?
Note:
I was able to work around this issue by monkey patching the
Sunspot::Rails.slave_config method. I added file called sunspot.rb in
configurations/initializers directory.
module Sunspot::Rails
def slave_config(sunspot_rails_configuration)
config = Sunspot::Configuration.build
config.solr.url = URI::HTTP.build(
:host => sunspot_rails_configuration.hostname,
:port => sunspot_rails_configuration.port,
:path => sunspot_rails_configuration.path
).to_s
config
end
end
Sunspot.session = Sunspot::Rails.build_session
I am not sure if this is the correct approach. Please let me know if I am missing something basic.