rails-informant 0.3.2 → 0.3.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: 76da3bf5c0eb0105ac095478e9d5a4f659fd126516a5b19aed187ced576016df
4
- data.tar.gz: 26b94c5787654d4f15feda27a10fd2bc7247a56643d9e5e01ef45f18d6dd93a3
3
+ metadata.gz: f3d333268d4996b1ccee39e08ad675d133b067be5b89b57dff6c553951fed09f
4
+ data.tar.gz: c6b1be1a6c014ce1c5a58ab90138a16e9a93cefdeb741b59d77dccd8a2387ec6
5
5
  SHA512:
6
- metadata.gz: 73fdd6e6a8fbac8f9a2d11bc3e6d3647b9db0d14bd5f563959a2fb20fb64f5d228c650f439be5fccceda5250cc2572a4c09bde2a437165c3e29e5291b0f0c97a
7
- data.tar.gz: 518259a2c96148552ef476ad9b223ec35186dc87a8bb2b41c58503cfb5eab09bebb5a3b7813062ab58518fdc405f0f7a9397da17c910929e2beec983fa3e54da
6
+ metadata.gz: 74f455bafd7f95401387211d742e2ddff3c56ed7bef1483a12835c3b7573cbbd69a8985d0792e4d8f7f45dfde7eb65012e49ad62c22d15cf9a590fe0e96908e1
7
+ data.tar.gz: 4b303b1ebc02fa906ba8cec9e78121784394cdc246b9963b69c3604824d78d75d4a6d27044cab95d148583c7cd95d9d0fcd675c5304115a01aa4b32a71435c11
@@ -33,8 +33,6 @@ module RailsInformant
33
33
  end
34
34
 
35
35
  def truncate_to_size(data)
36
- return data if data.is_a?(Hash) && data.size < 20
37
-
38
36
  json = data.to_json
39
37
  return data if json.bytesize <= MAX_CONTEXT_SIZE
40
38
 
@@ -47,6 +47,7 @@ module RailsInformant
47
47
  keep_ids = group.occurrences.order(created_at: :desc).limit(MAX_OCCURRENCES_PER_GROUP).select(:id)
48
48
  Occurrence.where(error_group_id: group.id).where.not(id: keep_ids).delete_all
49
49
  end
50
+
50
51
  def notify(group)
51
52
  return if Notifiers::CircuitBreaker.open?
52
53
  return unless RailsInformant.config.notifiers.any? { it.should_notify?(group) }
@@ -1,7 +1,6 @@
1
1
  require "json"
2
2
  require "net/http"
3
3
  require "uri"
4
- require "yaml"
5
4
 
6
5
  require_relative "version"
7
6
  require_relative "mcp/client"
@@ -3,26 +3,36 @@ module RailsInformant
3
3
  class CircuitBreaker
4
4
  FAILURE_THRESHOLD = 5
5
5
  RESET_TIMEOUT = 10.minutes
6
+ MUTEX = Mutex.new
7
+ private_constant :MUTEX
6
8
 
7
9
  class << self
8
10
  def open?
9
- return false if failure_count < FAILURE_THRESHOLD
10
-
11
- last_failure_at > RESET_TIMEOUT.ago
11
+ MUTEX.synchronize do
12
+ return false if failure_count < FAILURE_THRESHOLD
13
+ last_failure_at > RESET_TIMEOUT.ago
14
+ end
12
15
  end
13
16
 
14
17
  def record_failure
15
- @failure_count = failure_count + 1
16
- @last_failure_at = Time.current
18
+ MUTEX.synchronize do
19
+ @failure_count = failure_count + 1
20
+ @last_failure_at = Time.current
21
+ end
17
22
  end
18
23
 
19
24
  def record_success
20
- reset!
25
+ MUTEX.synchronize do
26
+ @failure_count = 0
27
+ @last_failure_at = nil
28
+ end
21
29
  end
22
30
 
23
31
  def reset!
24
- @failure_count = 0
25
- @last_failure_at = nil
32
+ MUTEX.synchronize do
33
+ @failure_count = 0
34
+ @last_failure_at = nil
35
+ end
26
36
  end
27
37
 
28
38
  private
@@ -18,7 +18,7 @@ module RailsInformant
18
18
 
19
19
  def build_payload(error_group, occurrence)
20
20
  {
21
- text: "#{error_group.error_class}: #{error_group.message.to_s.truncate(200)}",
21
+ text: "#{error_group.error_class}: #{error_group.message&.truncate(200)}",
22
22
  blocks: [
23
23
  header_block(error_group, occurrence),
24
24
  error_class_block(error_group),
@@ -44,7 +44,7 @@ module RailsInformant
44
44
  type: "section",
45
45
  text: {
46
46
  type: "mrkdwn",
47
- text: "*#{error_group.error_class}*\n#{error_group.message.to_s.truncate(200)}"
47
+ text: "*#{error_group.error_class}*\n#{error_group.message&.truncate(200)}"
48
48
  }
49
49
  }
50
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-informant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel López Prat