Class: CloudfujiNoticeObserver

Inherits:
Mongoid::Observer
  • Object
show all
Defined in:
app/observers/cloudfuji_notice_observer.rb

Instance Method Summary collapse

Instance Method Details

#after_create(notice) ⇒ Object



4
5
6
7
8
9
10
11
12
13
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
47
# File 'app/observers/cloudfuji_notice_observer.rb', line 4

def after_create(notice)
  if ::Cloudfuji::Platform.on_cloudfuji?
    @notice = notice
    @err    = notice.err
    @app    = notice.problem.app

    err_url = Rails.application.routes.url_helpers.app_err_url(@app, notice.problem, :host => ENV['CLOUDFUJI_DOMAIN'])

    human_message = notice_title(notice.err.problem)
    human_message += " - see more at #{err_url}"
    event = {
      :category => :error,
      :name     => :caught,
      :data     => {
        :human            => human_message,
        :error_ido_id     => @err.ido_id,
        :app_name         => @app.name,
        :environment_name => @notice.environment_name,
        :occurrences      => @notice.problem.notices_count,
        :message          => @notice.message,
        :app_backtrace    => @notice.app_backtrace,
        :request          => @notice.request,
        :source           => "Errbit",
        :url              => err_url
      }
    }

    if @notice.respond_to?(:user_attributes) && @notice.user_attributes.present?
      event[:data].merge! :user_attributes => {
                            :ido_id => @notice.user_attributes[:ido_id],
                            :email  => @notice.user_attributes[:email]}
    end

    puts "Publishing Cloudfuji Event: #{event.inspect}"

    ::Cloudfuji::Event.publish(event)

    puts "Notifying: #{@app.watchers.inspect}"
    @app.watchers.each do |watcher|
      ido_id = watcher.user.ido_id
      Cloudfuji::User.notify(ido_id, "Site Error", human_message, "site_error") unless ido_id.blank?
    end
  end
end