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
43
44
45
46
# File 'lib/newrelic/notificator.rb', line 14

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

  config = HashWithIndifferentAccess.new(new_relic_yml)[@stage]
  unless config
    log "Can't find settings section - #{@stage}"
    return
  end

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

  log "Uploading deployment to New Relic..."

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

  log "Uploaded deployment information to New Relic"

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