Class: Problem

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/problem.rb

Overview

Represents a single Problem. The problem may have been reported as various Errs, but the user has grouped the Errs together as belonging to the same problem.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_else_unresolved(fetch_all) ⇒ Object


53
54
55
56
57
58
59
# File 'app/models/problem.rb', line 53

def self.all_else_unresolved(fetch_all)
  if fetch_all
    all
  else
    where(:resolved => false)
  end
end

.in_date_range(date_range) ⇒ Object


122
123
124
# File 'app/models/problem.rb', line 122

def self.in_date_range(date_range)
  where(:first_notice_at.lte => date_range.end).where("$or" => [{:resolved_at => nil}, {:resolved_at.gte => date_range.begin}])
end

.in_env(env) ⇒ Object


61
62
63
# File 'app/models/problem.rb', line 61

def self.in_env(env)
  env.present? ? where(:environment => env) : scoped
end

.merge!(*problems) ⇒ Object


89
90
91
# File 'app/models/problem.rb', line 89

def self.merge!(*problems)
  ProblemMerge.new(problems).merge
end

.ordered_by(sort, order) ⇒ Object


111
112
113
114
115
116
117
118
119
120
# File 'app/models/problem.rb', line 111

def self.ordered_by(sort, order)
  case sort
  when "app";            order_by(["app_name", order])
  when "message";        order_by(["message", order])
  when "last_notice_at"; order_by(["last_notice_at", order])
  when "last_deploy_at"; order_by(["last_deploy_at", order])
  when "count";          order_by(["notices_count", order])
  else raise("\"#{sort}\" is not a recognized sort")
  end
end

.search(value) ⇒ Object


157
158
159
160
161
162
163
164
165
# File 'app/models/problem.rb', line 157

def self.search(value)
  any_of(
    {:error_class => /#{value}/i},
    {:where => /#{value}/i},
    {:message => /#{value}/i},
    {:app_name => /#{value}/i},
    {:environment => /#{value}/i}
  )
end

Instance Method Details

#cache_app_attributesObject


131
132
133
134
135
136
137
138
139
140
141
# File 'app/models/problem.rb', line 131

def cache_app_attributes
  if app
    self.app_name = app.name
    self.last_deploy_at = if (last_deploy = app.deploys.where(:environment => self.environment).last)
      last_deploy.created_at.utc
    end
    collection.find('_id' => self.id)
              .update({'$set' => {'app_name' => self.app_name,
                        'last_deploy_at' => self.last_deploy_at.try(:utc)}})
  end
end

#issue_typeObject


151
152
153
154
155
# File 'app/models/problem.rb', line 151

def issue_type
  # Return issue_type if configured, but fall back to detecting app's issue tracker
  attributes['issue_type'] ||=
  (app.issue_tracker_configured? && app.issue_tracker.type_tracker) || nil
end

#merged?Boolean

Returns:

  • (Boolean)

93
94
95
# File 'app/models/problem.rb', line 93

def merged?
  errs.length > 1
end

#noticesObject


72
73
74
# File 'app/models/problem.rb', line 72

def notices
  Notice.for_errs(errs).ordered
end

#remove_cached_notice_attributes(notice) ⇒ Object


143
144
145
146
147
148
149
# File 'app/models/problem.rb', line 143

def remove_cached_notice_attributes(notice)
  update_attributes!(
    :messages    => attribute_count_descrease(:messages, notice.message),
    :hosts       => attribute_count_descrease(:hosts, notice.host),
    :user_agents => attribute_count_descrease(:user_agents, notice.user_agent_string)
  )
end

#reset_cached_attributesObject


127
128
129
# File 'app/models/problem.rb', line 127

def reset_cached_attributes
  ProblemUpdaterCache.new(self).update
end

#resolve!Object


76
77
78
# File 'app/models/problem.rb', line 76

def resolve!
  self.update_attributes!(:resolved => true, :resolved_at => Time.now)
end

#unmerge!Object


97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/models/problem.rb', line 97

def unmerge!
  attrs = {:error_class => error_class, :environment => environment}
  problem_errs = errs.to_a
  problem_errs.shift
  [self] + problem_errs.map(&:id).map do |err_id|
    err = Err.find(err_id)
    app.problems.create(attrs).tap do |new_problem|
      err.update_attribute(:problem_id, new_problem.id)
      new_problem.reset_cached_attributes
    end
  end
end

#unresolve!Object


80
81
82
# File 'app/models/problem.rb', line 80

def unresolve!
  self.update_attributes!(:resolved => false, :resolved_at => nil)
end

#unresolved?Boolean

Returns:

  • (Boolean)

84
85
86
# File 'app/models/problem.rb', line 84

def unresolved?
  !resolved?
end

#urlObject


65
66
67
68
69
70
# File 'app/models/problem.rb', line 65

def url
  Rails.application.routes.url_helpers.app_problem_url(app, self,
    :host => Errbit::Config.host,
    :port => Errbit::Config.port
  )
end