#!/usr/bin/env ruby

require "rubygems"
require "active_message"
require "daemons"

APP_PATH    = File.expand_path(File.join('.', 'config/application.rb'))
CONFIG_PATH = File.expand_path(File.join('.', 'config/active_message.yml'))
# ENV["RAILS_ENV"] ||= ("development")

Daemons.run_proc('active_message_worker') do
  if File.exist? APP_PATH
    require APP_PATH
    Rails.application.require_environment!
  end

  if File.exist? CONFIG_PATH
    ActiveMessage::Configuration.load_from_file(CONFIG_PATH)
  end

  ActiveMessage.connect
  worker = ActiveMessage::Worker.new
  worker.run
end