Last Updated: February 25, 2016
·
875
· cgarvis

Ping Event for Rails & Mongoid

I use New Relic to keep my heroku dyno from falling into the 1-hour of inactivity. This little controller/action is what I use. It also checks if the MongoDB connection is still alive for an added bonus.

class PingController < ApplicationController
  def ping
    if Mongoid.default_session.command(ping: 1)
      render :text => "pong"
    else
      render :status => 500
    end
  end
end