Class: Minicron::SMS

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

Overview

Allows the sending of SMS alerts via Twilio

Instance Method Summary collapse

Constructor Details

#initializeSMS

Used to set up on the twilio client


7
8
9
10
11
12
13
# File 'lib/minicron/alert/sms.rb', line 7

def initialize
  # Get an instance of the twilio client
  @client = Twilio::REST::Client.new(
    Minicron.config['alerts']['sms']['twilio']['account_sid'],
    Minicron.config['alerts']['sms']['twilio']['auth_token']
  )
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


24
25
26
27
28
29
30
31
32
33
# File 'lib/minicron/alert/sms.rb', line 24

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

#send(from, to, message) ⇒ Object

Send an sms alert

Parameters:

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

40
41
42
43
44
45
46
# File 'lib/minicron/alert/sms.rb', line 40

def send(from, to, message)
  @client..messages.create(
    :from => from,
    :to => to,
    :body => message
  )
end