using apn_sender on heroku - ruby-on-rails-3

We built an api in rails and are hosting it on heroku and using apn_sender to do the push notifications. We got everything running locally with apn_sender but when we push it to heroku and run
heroku rake apn:sender
we get the following error "Connection refused - Unable to connect to Redis on 127.0.0.1:6379"
We added the redistogo addon.
UPDATE
We added a resque.rb initializer:
require 'resque'
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
and called to start up the worker
heroku rake environment apn:sender
and everything seemed to work.

Ok, so after further testing, the update I put in above doesn't work for very long before it crashes. We then followed this http://blog.redistogo.com/2010/07/26/resque-with-redis-to-go/
Changing
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
end
to
task "apn:setup" => :environment do
ENV['QUEUE'] = '*'
end
and
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
to
desc "Alias for apn:work (To run workers on Heroku)"
task "jobs:work" => "apn:work"
and it worked like a charm. Also note, that we had to add a worker dyno in heroku, which costs .05/hour or $35/month.

Related

Rails App on AWS Elasticbeanstalk mail send fails with ESMTP No Relay Access Allowed From IP

I have a rails app that I have deployed to AWS Elastic Beanstalk. The app uses devise to handle user authentication, and its set to be able to invite users.
My issue is that when I try to invite a user, I get the following error:
Net::SMTPFatalError (554 secureserver.net ESMTP No Relay Access Allowed From <my_eb_assigned_ip>
(I am hosting the domain on GoDaddy).
In development, the mailer functionality works fine; my smtp settings are set to (common to all environments):
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtpout.secureserver.net",
:port => 80,
:domain => "www.my_domain.com",
:authentication => :plain,
:user_name => "do-not-reply#my_domain.com",
:password => my_pass,
}
And in my production.rb config file:
config.action_mailer.default_url_options = { :host => 'aws_sb.elasticbeanstalk.com' }
Is there another setting I have to enable in Elasticbeanstalk to allow relay access? Or am I missing a production specific setting from my rails configuration?
I figured out it was the port value that I was setting....when I switched the port to 25, it works in production. However, for development, port 25 wasn't working; it would only work in dev when the port was 80.
So I ended up moving the entire smtp mailer settings into the environment specific settings (from the config/environment.rb file), and setting the production port to 25, and the development port to 80, and that appeared to make both environments work.
Edit: After another push, I was seeing the same issue, and none of the ports I tried were resolving the issue. So I ended up switching all my mail functionality to be sent through Amazon SES, and that appears to be functioning great so far.

mandrill send e-mail from localhost

I'm using Mandrill to build a feedback form for users on the website (they fill the form and send me an e-mail).
I want to test the e-mail functionality in development. I use unicorn as a server and my local address is 0.0.0:8080
However I get a 500 server error, Net::SMTPServerBusy : Relay Access Denied
I followed the Heroku instructions step by step.
Here is m application.rb configuration:
config.action_mailer.smtp_settings = {
:address => 'smtp.mandrillapp.com',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['MANDRILL_USERNAME'],
:password => ENV['MANDRILL_APIKEY']
}
ActionMailer::Base.delivery_method = :smtp
I followed the instructions on mandrill/heroku web page to set up.
I have a .env file set up with a MANDRILL_USERNAME and my MANDRILL_APIKEY
Here is my ActionMailer file:
class FeedbackMailer < ActionMailer::Base
default :from => ""
default :to => "xxx#stanford.edu"
default :subject => "feedback about xxx"
def send_feedback(message)
#debugger
#message = message
mail(:from => message[:sender_email])
end
end
Any help would be appreciated.
I can confirm e-mails get sent in production.
If all of your settings are working in production but not locally, there are a couple of possibilities:
How are you loading the variables from .env to ENV? It's possible the environment variables aren't getting loaded as expected locally. If you hard code the credentials locally, does it work?
You could be running in to an issue with the port or outbound SMTP traffic being blocked. Consider trying port 2525, as it may be less likely to be blocked by local ISPs. Port 465 with SSL enabled may also work even if your ISP is blocking other SMTP traffic

Getting Faraday::Error::ConnectionFailed when connecting from heroku rails app

My company has a simple oauth server at https://auth.vitalvu.com
I'm developing a rails app that needs to make requests to that server (via the omniauth-oauth2 gem). When I try to run the app on Heroku I get the error:
Faraday::Error::ConnectionFailed: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
I've tested it as described here.
From the app's rails console on my local machine
connection = Faraday::Connection.new 'https://auth.vitalvu.com'
connection.get '/ping.json'
works just fine.
However, after pushing the app to Heroku, heroku run rails console
connection = Faraday::Connection.new 'https://auth.vitalvu.com'
connection.get '/ping.json'
results in the faraday error and
connection = Faraday::Connection.new 'https://auth.vitalvu.com', :ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}
connection.get '/ping.json'
results in the faraday error and
connection = Faraday::Connection.new 'https://auth.vitalvu.com', :ssl => {:ca_path => "/etc/ssl/certs"}
connection.get '/ping.json'
results in the faraday error
I'm not sure what else to try. Suggestions?
I run heroku restart three times - and than finally is starts to work.

migration fails on heroku due to activeadmin mailer

I am deploying an app to heroku and the app is on rails 3.2 and I have active admin gem installed.
When I run rake db:migrate it fails due to the following error
== DeviseCreateAdminUsers: migrating =========================================
-- create_table(:admin_users)
-> 0.0823s
Sent mail to admin#example.com (3228ms)
rake aborted!
An error has occurred, this and all later migrations canceled:
Connection refused - connect(2)
Wondering what I need to do to fix this. It seems that the Devise gem or ActiveAdmin needs to send mail during the migration process and because it can't if fails.
Try installing the Sendgrid addon:
heroku addons:add sendgrid:starter
If you are deploying to the Aspen or Bamboo stacks, it should work right away. If you are using the Cedar stack, you need to add an additional initializer:
#config/initializers/mail.rb
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com'
}
ActionMailer::Base.delivery_method = :smtp
Taken from: http://devcenter.heroku.com/articles/sendgrid
This is confusing me a little:
Connection refused - connect(2)
Do you have your mail setup? Are you using SendGrid or similar? Remember that Heroku don't provide email services directly.
http://devcenter.heroku.com/articles/smtp

How to make cucumber/selenium run Thin server instead of Webrick

where do I have to setup or configure to fire cucumber/selenium test to run Thin server instead of the default Webrick server?
To explicitly setup Thin, create a file within the features/support directory with the following:
Capybara.server do |app, port|
require 'rack/handler/thin'
Rack::Handler::Thin.run(app, :Port => port)
end