midnight_ride 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d140df1f7728b4afec68c9e448c08873026dae8253e5c09ae48701c5347982b5
4
- data.tar.gz: b536db431eb18cba490098ec50472d237da48174f2147f6be0c79c9f54178e0b
3
+ metadata.gz: 3f2e2c482f35250675a4dc63f12ba46436b2e132d8cff3dc4e94aa739895689b
4
+ data.tar.gz: 37b3c860d3322578f1bf40143b7759e02ac4391354d04faac4386882ba5bc7db
5
5
  SHA512:
6
- metadata.gz: 53bfff4dd359ddfcd7a1e8181c68dd7b5a708cc74c1d9fca6bb60bb3450516342ed8a0b5e44a6e35254671e17fd16f0096fbc337180f434362d551776472989b
7
- data.tar.gz: faec529791bb15107c64f9812d2a6dd3587436ebef93ddc6026459eda879a9f1effdc8f1a11fe5d8dec37d02b629047592a87e257a69e6ba5c88cd38816f40f9
6
+ metadata.gz: b6eb066d360191f6ef35452069812f96855b484a54b0d5fbd4ca6bd1b0022629a33a62dada9bd2990df63c2908c325908e0183834174f9b9b40d4d40c24f8f0e
7
+ data.tar.gz: 9120e4ebadbdbb87cce2f8e2b3dee1b04bb8e0c98a03ccf706fc9ec9cd4eed49a505ce568d275105f8c5dd01516188502eb0d986cadd3553fd35609b1eadbc36
data/README.md CHANGED
@@ -123,7 +123,9 @@ MidnightRide.resolve(ids)
123
123
  ```
124
124
 
125
125
  for instance with `bin/rails runner 'MidnightRide.resolve(ARGV)' 90 91`.
126
- Errors that haven’t happened for a week resolve themselves anyway.
126
+ It also resolves the errors that count as one with those, which no commit
127
+ names, since only one of them was alerted about. Errors that haven’t
128
+ happened for a week resolve themselves anyway.
127
129
 
128
130
  ## License
129
131
 
@@ -72,12 +72,30 @@ module MidnightRide
72
72
  Net::HTTP.post(URI(url), body.to_json, {"Content-Type" => "application/json"}.merge(headers))
73
73
  end
74
74
 
75
- private
76
-
75
+ # Errors with the same key count as one: each alerts once, and resolving
76
+ # one resolves them all.
77
77
  def key
78
78
  @key ||= "midnight_ride/#{Digest::SHA256.hexdigest([exception_class, without_values(message), without_numbers(location)].join("\n"))}"
79
79
  end
80
80
 
81
+ # The ids of the alerts that count as one with an alert of the given ids
82
+ def self.alike alerts, ids
83
+ keys = alerts.select { ids.include?(it.id) }.map(&:key)
84
+ alerts.select { keys.include?(it.key) }.map(&:id)
85
+ end
86
+
87
+ # One alert for each group of alerts that count as one, the oldest's,
88
+ # with how often they all happened
89
+ def self.reminders alerts
90
+ alerts.group_by(&:key).values.map do |group|
91
+ first = group.min_by(&:id)
92
+ new(id: first.id, exception_class: first.exception_class, message: first.message,
93
+ backtrace: first.backtrace, still_happening: group.sum { it.still_happening.to_i })
94
+ end
95
+ end
96
+
97
+ private
98
+
81
99
  def seen?
82
100
  MidnightRide.cache.exist?(key)
83
101
  end
@@ -17,17 +17,20 @@ module MidnightRide
17
17
  end
18
18
 
19
19
  # Once a day, alerts again about each unresolved error that still happened
20
- # in the last day, with how often, and starts another session for it.
21
- # Errors new in the last day were alerted about already.
20
+ # in the last day, with how often, and starts another session for it,
21
+ # once for errors that count as one. Errors new in the last day were
22
+ # alerted about already.
22
23
  class RemindersJob < ActiveJob::Base
23
24
  def perform
24
25
  since = 1.day.ago
25
26
  counts = SolidErrors::Occurrence.where(created_at: since..).group(:error_id).count
27
+ errors = SolidErrors::Error.unresolved.where(id: counts.keys, created_at: ...since)
28
+ alerts = errors.map { MidnightRide.alert_for(it, still_happening: counts[it.id]) }
26
29
 
27
- SolidErrors::Error.unresolved.where(id: counts.keys, created_at: ...since).find_each do |error|
28
- MidnightRide.alert(error, still_happening: counts[error.id])
30
+ Alert.reminders(alerts).each do |alert|
31
+ alert.deliver
29
32
  rescue => e
30
- MidnightRide.logger.error("MidnightRide::RemindersJob failed for error #{error.id}: #{e.class}: #{e.message}")
33
+ MidnightRide.logger.error("MidnightRide::RemindersJob failed for error #{alert.id}: #{e.class}: #{e.message}")
31
34
  end
32
35
  end
33
36
  end
@@ -43,12 +46,16 @@ module MidnightRide
43
46
  end
44
47
 
45
48
  def self.alert error, **options
49
+ alert_for(error, **options).deliver
50
+ end
51
+
52
+ def self.alert_for error, **options
46
53
  Alert.new(
47
54
  id: error.id,
48
55
  exception_class: error.exception_class,
49
56
  message: error.message,
50
57
  backtrace: error.occurrences.order(:id).last&.backtrace,
51
58
  **options
52
- ).deliver
59
+ )
53
60
  end
54
61
  end
@@ -1,3 +1,3 @@
1
1
  module MidnightRide
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/midnight_ride.rb CHANGED
@@ -59,11 +59,16 @@ module MidnightRide
59
59
  (@root || Rails.root).to_s
60
60
  end
61
61
 
62
- # Resolves the Solid Errors errors with the given ids, so they alert
63
- # again if they come back. For the server's deploys, which resolve the
64
- # errors the deployed commits name (see the README).
62
+ # Resolves the Solid Errors errors with the given ids, and the unresolved
63
+ # ones that count as one with them, which no commit names, since only
64
+ # one of them was alerted about. They alert again if they come back. For
65
+ # the server's deploys, which resolve the errors the deployed commits
66
+ # name (see the README).
65
67
  def resolve ids
66
- SolidErrors::Error.unresolved.where(id: ids).update_all(resolved_at: Time.current)
68
+ ids = ids.map(&:to_i)
69
+ unresolved = SolidErrors::Error.unresolved.to_a
70
+ alike = Alert.alike(unresolved.map { alert_for(it) }, ids)
71
+ SolidErrors::Error.unresolved.where(id: ids | alike).update_all(resolved_at: Time.current)
67
72
  end
68
73
  end
69
74
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midnight_ride
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Hackethal