AnarchoEnte
AnarchoEnte

Reputation: 568

Ruby - Asynchronous Mailing

I'm quite new to Ruby on Rails and want to send an e-mail asynchronously to make my app respond faster. The synchronous sending works fine and would be my alternative.

I've found some sites and defined the gems 'resque_mailer', 'redis' and 'resque' in my Gemfile and installed them via the bundle install command. My mailer looks like:

class Contact < ActionMailer::Base 
include Resque::Mailer  

default from: "<private>"

  def contact(email, bandName, respondMail, message)
    @message = message
    @respondMail = respondMail
    @bandName = bandName

    mail(:to => email,
         :subject => "subject")
  end
end

The Controller-Call to send the mail looks like:

Contact.contact(band.email, band.name, params[:respondMail].to_s, params[:message].to_s).deliver

If I try to send my mail now asynchronously I'm getting the following error which is caused by the "contact" call:

Timed out connecting to Redis on 127.0.0.1:6379

Unfortunately I've got no idea how to solve this. Can someone please tell me which steps I must make to send a mail asynchronously? If possible there should be no extra database columns.

Upvotes: 2

Views: 1234

Answers (1)

Yves Senn
Yves Senn

Reputation: 1996

In order for resque and resque_mailer to work you need to install redis. You can find more about redis here: http://redis.io/download

If you are new to rails, all the external tools and dependencies can be quite overwhelming. If you don't have an application with extreme load you should consider using a simpler job queue like https://github.com/collectiveidea/delayed_job. It does not depend on further external services and uses your current database to store the jobs. The only thing you need to do is to keep the workers up.

Upvotes: 1

Related Questions