Scott Watermasysk

Still Learning

Async Emails With Sorcery

For KickoffLabs, we rolled our own authentication. This worked really well, but doing it (even if we packaged it up) for future projects is less than appealing.

I have used/tried Devise, Clearance, and AuthLogic but none of them seemed to fit.

Enter Sorcery. Sorcery is a relatively new player in the rails authentication arms race.

So far, I am really liking Sorcery[1]. It stays out of the way, has decent documentation, useful testing helpers, etc.

Unfortunately, out of the box, Sorcery sends emails inline (same UI thread). In local development, this is not an issue. However, in production is this not acceptable.

Looking through the Sorcery source code, I did not see a configuration hook related to this. But with a little bit of monkey patching, we can alter the behavior:

1
2
3
4
5
6
7
8
9
10
module Sorcery
  module Model
    module InstanceMethods
      def generic_send_email(method, mailer)
        config = sorcery_config
        mail = config.send(mailer).enqueue.send(config.send(method),self.id)
      end
    end
  end
end

In this case, I am simply overriding the generic_send_email method. The enqueue method comes from my own Resque Mail Queue gem. You could very easily do something similar with delayed_job, etc.

Since I am using Resque, I also updated my mailer actions to use the user (model) id instead of the user model. Otherwise, nothing else in Sorcery needs to change.

I doubt this is the ideal way to ‘fix’ this issue, but it works for now and allows me to move forward.

[1] Well, I should clarify I am liking the ActiveRecord adapter. I haven’t been able to get the Mongoid one working properly…but that could be something on my side.

Heroku SSL via DNSimple

If you google for Heroku SSL you will find a surprisingly long list of blog posts usually with many steps.

However, it is actually much easier than what most of them list, especially if you are using DNSimple (note: affiliate link).

Here is how to setup a Hostname Based certificate on Heroku:

Static Files Using Sinatra::Base on Heroku

I deployed a small Sinatra app last night to Heroku for the new KickoffLabs API.

Most of the Sinatra apps I have deployed in the past have been small prototypes and used the inline Sinatra app style.

However, in this case, I made the decision early on to use the Sinatra::Base class style since we plan on growing the API codebase (ie, we are going to keep it around for a long time).

Multiple Smtp Servers With Action Mailer

We recently started using PostMark on KickoffLabs. So far the service has been excellent. Unfortunately, not all of our emails fit their terms of service. I looked around for how configure an addition SMTP server via Action Mailer (and Mail gem). Surprisingly, this is not supported.