Class: NewRelic::Notificator

Inherits:
Object
  • Object
show all
Defined in:
lib/newrelic/notificator.rb

Instance Method Summary collapse

Constructor Details

#initialize(stage, revision, user, newrelic_config_file) ⇒ Notificator

Returns a new instance of Notificator.



7
8
9
10
11
12
# File 'lib/newrelic/notificator.rb', line 7

def initialize(stage, revision, user, newrelic_config_file)
  @stage = stage
  @revision = revision
  @user = user
  @newrelic_config_file = newrelic_config_file
end

Instance Method Details

#notifyObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/newrelic/notificator.rb', line 14

def notify
  new_relic_yml = YAML.load_file(@newrelic_config_file) rescue nil
  unless new_relic_yml
    puts "Can't open New Relic config file!"
    return
  end

  config = HashWithIndifferentAccess.new(new_relic_yml)[@stage]

  deploy_options = {
    :revision    => @revision,
    :environment => @stage,
    :user        => @user,
    :description => config[:description],
    :license_key => config[:license_key],
    :appname     => config[:app_name]
  }

  puts "Uploading deployment to New Relic..."

  deployment = NewRelic::Cli::Deployments.new deploy_options
  deployment.run

  puts "Uploaded deployment information to New Relic"

rescue => e
  puts "Unable to notify New Relic of the deployment... skipping"
  puts "Error creating New Relic deployment (#{e})\n#{e.message})\n#{e.backtrace.join("\n")}"
end