Sha256: da465480f13e77283d148271e678c7ab1551c38e9d452b8b367331ccad45702a

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'ar_mailer_aws'
require 'daemons'

require 'ostruct'
require 'optparse'

# require Rails environment expect running tests
name = File.basename $0
unless name == 'rspec'
  begin
    require Dir.pwd + '/config/environment'
    ActiveRecord::Base.connection.disconnect!
  rescue LoadError
    <<-EOF
      #{name} must be run from a Rails application's root to deliver email.
      #{Dir.pwd} does not appear to be a Rails application root.
    EOF
  end
end

options = ArMailerAWS.parse_options(ARGV)
daemon_options = {multiple: true}
daemon_options.update(dir_mode: :normal, dir: options.pid_dir) if options.pid_dir

Daemons.run_proc('ar_mailer_aws', daemon_options) do
  # handle log files
  if defined? Rails
    ActiveRecord::Base.establish_connection
    logger = ActiveSupport::BufferedLogger.new(Rails.root.join("log/#{Rails.env}.log"))
    ActiveRecord::Base.logger = logger unless Rails.env.production?
    Rails.logger = ActionMailer::Base.logger = logger
  end
  if ArMailerAWS.logger.respond_to?(:reopen)
    ArMailerAWS.logger.reopen
    ArMailerAWS.logger.info 'Started daemon'
  end
  AWS.config.logger.reopen if AWS.config.logger.respond_to?(:reopen)

  # run mailer
  ArMailerAWS.run(options)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ar_mailer_aws-0.0.3 bin/ar_mailer_aws