breaker_machines 0.3.0 → 0.4.0

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.
@@ -23,10 +23,10 @@ module BreakerMachines
23
23
  circuit_data = @circuits[circuit_name]
24
24
  return nil unless circuit_data
25
25
 
26
- {
26
+ BreakerMachines::Status.new(
27
27
  status: circuit_data[:status],
28
28
  opened_at: circuit_data[:opened_at]
29
- }
29
+ )
30
30
  end
31
31
 
32
32
  def set_status(circuit_name, status, opened_at = nil)
@@ -130,7 +130,7 @@ module BreakerMachines
130
130
  end
131
131
 
132
132
  def monotonic_time
133
- Process.clock_gettime(Process::CLOCK_MONOTONIC)
133
+ BreakerMachines.monotonic_time
134
134
  end
135
135
  end
136
136
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BreakerMachines
4
+ # Represents the status of a circuit from storage
5
+ # @return [Symbol] status - the circuit status (:open, :closed, :half_open)
6
+ # @return [Float, nil] opened_at - the monotonic time when the circuit was opened
7
+ Status = Data.define(:status, :opened_at)
8
+
9
+ # Represents statistical information about a circuit
10
+ Stats = Data.define(
11
+ :state,
12
+ :failure_count,
13
+ :success_count,
14
+ :last_failure_at,
15
+ :opened_at,
16
+ :half_open_attempts,
17
+ :half_open_successes
18
+ )
19
+
20
+ # Represents information about the last error that occurred
21
+ # @return [String] error_class - the error class name
22
+ # @return [String] message - the error message
23
+ # @return [Float, nil] occurred_at - the monotonic time when the error occurred
24
+ ErrorInfo = Data.define(:error_class, :message, :occurred_at)
25
+
26
+ # Represents cascade information for cascading circuits
27
+ CascadeInfo = Data.define(
28
+ :dependent_circuits,
29
+ :emergency_protocol,
30
+ :cascade_triggered_at,
31
+ :dependent_status
32
+ )
33
+
34
+ # Represents an event in the circuit's event log
35
+ # @return [Symbol] type - the event type (:success, :failure, :state_change)
36
+ # @return [Float] timestamp - the monotonic timestamp
37
+ # @return [Float] duration - the duration in milliseconds
38
+ # @return [String, nil] error - the error message if applicable
39
+ # @return [Symbol, nil] new_state - the new state if this was a state change
40
+ Event = Data.define(:type, :timestamp, :duration, :error, :new_state)
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BreakerMachines
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -3,11 +3,14 @@
3
3
  require 'zeitwerk'
4
4
  require 'active_support'
5
5
  require 'active_support/core_ext'
6
+ require 'state_machines'
6
7
  require_relative 'breaker_machines/errors'
8
+ require_relative 'breaker_machines/types'
7
9
 
8
10
  loader = Zeitwerk::Loader.for_gem
9
11
  loader.inflector.inflect('dsl' => 'DSL')
10
12
  loader.ignore("#{__dir__}/breaker_machines/errors.rb")
13
+ loader.ignore("#{__dir__}/breaker_machines/types.rb")
11
14
  loader.ignore("#{__dir__}/breaker_machines/console.rb")
12
15
  loader.ignore("#{__dir__}/breaker_machines/async_support.rb")
13
16
  loader.ignore("#{__dir__}/breaker_machines/hedged_async_support.rb")
@@ -77,6 +80,15 @@ module BreakerMachines
77
80
  def registry
78
81
  Registry.instance
79
82
  end
83
+
84
+ # Returns the current monotonic time in seconds.
85
+ # Monotonic time is guaranteed to always increase and is not affected
86
+ # by system clock adjustments, making it ideal for measuring durations.
87
+ #
88
+ # @return [Float] current monotonic time in seconds
89
+ def monotonic_time
90
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
91
+ end
80
92
  end
81
93
 
82
94
  # Set up notifications on first use
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breaker_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
- bindir: exe
8
+ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '8.0'
18
+ version: '7.2'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '8.0'
25
+ version: '7.2'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: concurrent-ruby
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -43,14 +43,14 @@ dependencies:
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 0.31.0
46
+ version: 0.50.0
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 0.31.0
53
+ version: 0.50.0
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: zeitwerk
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -109,6 +109,7 @@ files:
109
109
  - README.md
110
110
  - lib/breaker_machines.rb
111
111
  - lib/breaker_machines/async_support.rb
112
+ - lib/breaker_machines/cascading_circuit.rb
112
113
  - lib/breaker_machines/circuit.rb
113
114
  - lib/breaker_machines/circuit/callbacks.rb
114
115
  - lib/breaker_machines/circuit/configuration.rb
@@ -117,17 +118,23 @@ files:
117
118
  - lib/breaker_machines/circuit/state_management.rb
118
119
  - lib/breaker_machines/console.rb
119
120
  - lib/breaker_machines/dsl.rb
121
+ - lib/breaker_machines/dsl/cascading_circuit_builder.rb
122
+ - lib/breaker_machines/dsl/circuit_builder.rb
123
+ - lib/breaker_machines/dsl/hedged_builder.rb
124
+ - lib/breaker_machines/dsl/parallel_fallback_wrapper.rb
120
125
  - lib/breaker_machines/errors.rb
121
126
  - lib/breaker_machines/hedged_async_support.rb
122
127
  - lib/breaker_machines/hedged_execution.rb
123
128
  - lib/breaker_machines/registry.rb
124
129
  - lib/breaker_machines/storage.rb
130
+ - lib/breaker_machines/storage/backend_state.rb
125
131
  - lib/breaker_machines/storage/base.rb
126
132
  - lib/breaker_machines/storage/bucket_memory.rb
127
133
  - lib/breaker_machines/storage/cache.rb
128
134
  - lib/breaker_machines/storage/fallback_chain.rb
129
135
  - lib/breaker_machines/storage/memory.rb
130
136
  - lib/breaker_machines/storage/null.rb
137
+ - lib/breaker_machines/types.rb
131
138
  - lib/breaker_machines/version.rb
132
139
  - sig/README.md
133
140
  - sig/all.rbs