Module: ArMailerAWS

Defined in:
lib/ar_mailer_aws.rb,
lib/ar_mailer_aws/mailer.rb,
lib/ar_mailer_aws/sender.rb,
lib/ar_mailer_aws/railtie.rb,
lib/ar_mailer_aws/version.rb

Defined Under Namespace

Classes: Mailer, Railtie, Sender

Constant Summary collapse

VERSION =
'0.0.2'
@@email_class =
'BatchEmail'
@@ses_options =
{}

Class Method Summary collapse

Class Method Details

.parse_options(args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ar_mailer_aws.rb', line 37

def parse_options(args)
  start_i = args.index('--').try(:succ) || 0
  args = args[start_i..-1]
  options = OpenStruct.new

  OptionParser.new do |opts|
    options.batch_size = 100
    options.delay = 180
    options.quota = 10_000
    options.rate = 5
    options.max_age = 3600 * 24 * 7

    opts.banner = <<-TXT.strip_heredoc
      Usage: ar_mailer_aws <command> <options> -- <application options>

      * where <command> is one of:
        start         start an instance of the application
        stop          stop all instances of the application
        restart       stop all instances and restart them afterwards
        reload        send a SIGHUP to all instances of the application
        run           start the application and stay on top
        zap           set the application to a stopped state
        status        show status (PID) of application instances

      * where <options> may contain several of the following:

          -t, --ontop                      Stay on top (does not daemonize)
          -f, --force                      Force operation
          -n, --no_wait                    Do not wait for processes to stop

      * and where <application options> may contain several of the following:

    TXT

    opts.on('-b', '--batch-size BATCH_SIZE', 'Maximum number of emails to send per delay',
            "Default: #{options.batch_size}", Integer) do |batch_size|
      options.batch_size = batch_size
    end

    opts.on('-d', '--delay DELAY', 'Delay between checks for new mail in the database',
            "Default: #{options.delay}", Integer) do |delay|
      options.delay = delay
    end

    opts.on('-q', '--quota QUOTA', 'Daily quota for sending emails', "Default: #{options.quota}", Integer) do |quota|
      options.quota = quota
    end

    opts.on('-r', '--rate RATE', 'Maximum number of emails send per second',
            "Default: #{options.rate}", Integer) do |rate|
      options.rate = rate
    end

    opts.on('-m', '--max-age MAX_AGE',
            'Maxmimum age for an email. After this',
            'it will be removed from the queue.',
            'Set to 0 to disable queue cleanup.',
            "Default: #{options.max_age} seconds", Integer) do |max_age|
      options.max_age = max_age
    end

    opts.on('-p', '--pid-dir DIRECTORY', 'Directory for storing pid file',
            'Default: Stored in current directory (named `ar_mailer_aws.pid`)') do |pid_dir|
      options.pid_dir = pid_dir
    end

    opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
      options.verbose = v
    end

    opts.on_tail('-h', '--help', 'Show this message') do
      puts opts
      exit
    end

  end.parse!(args)

  options
end

.run(options) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/ar_mailer_aws.rb', line 29

def run(options)
  sender = Sender.new(options)
  loop do
    sender.send_batch
    sleep sender.options.delay
  end
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (ArMailerAWS)

    the object that the method was called on



25
26
27
# File 'lib/ar_mailer_aws.rb', line 25

def setup
  yield self
end