Class: Minicron::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/minicron/alert/email.rb

Overview

Allows the sending of email alerts

Instance Method Summary collapse

Constructor Details

#initializeEmail

Configure the mail client


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/minicron/alert/email.rb', line 7

def initialize
  Mail.defaults do
    delivery_method(
      :smtp,
      :address => Minicron.config['alerts']['email']['smtp']['address'],
      :port => Minicron.config['alerts']['email']['smtp']['port'],
      :domain => Minicron.config['alerts']['email']['smtp']['domain'],
      :user_name => Minicron.config['alerts']['email']['smtp']['user_name'],
      :password => Minicron.config['alerts']['email']['smtp']['password'],
      :enable_starttls_auto => Minicron.config['alerts']['email']['smtp']['enable_starttls_auto']
    )
  end
end

Instance Method Details

#get_message(options = {}) ⇒ Object

Return the message for an alert

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • job (Minicron::Hub::Job)

    a job instance

  • kind (String)

    'fail' or 'miss'

  • schedule_id (Integer, nil)

    only applies to 'miss' alerts

  • execution_id (Integer, nil)

    only used by 'fail' alerts

  • job_id (Integer)

    used to look up the job name for the alert message

  • expected_at (Time)

    when the schedule was expected to execute

  • medium (String)

    the medium to send the alert via


29
30
31
32
33
34
35
36
37
38
# File 'lib/minicron/alert/email.rb', line 29

def get_message(options = {})
  case options[:kind]
  when 'miss'
    "Job ##{options[:job_id]} '#{options[:job].name}' failed to execute at its expected time: #{options[:expected_at]}."
  when 'fail'
    "Execution ##{options[:execution_id]} of Job ##{options[:job_id]} '#{options[:job].name}' failed."
  else
    fail Exception, "The kind '#{options[:kind]} is not supported!"
  end
end

#send(from, to, subject, message) ⇒ Object

Send an email alert

Parameters:

  • from (String)
  • to (String)
  • subject (String)
  • message (String)

46
47
48
49
50
51
52
53
# File 'lib/minicron/alert/email.rb', line 46

def send(from, to, subject, message)
  Mail.deliver do
    to       to
    from     from
    subject  subject
    body     message
  end
end