Class: SelfDestruct::Agent
- Inherits:
-
Object
- Object
- SelfDestruct::Agent
- Defined in:
- lib/self_destruct.rb
Constant Summary collapse
- DEFAULT_RATIO_THRESHOLD =
5
- DEFAULT_GRACE_PERIOD =
in seconds
60
- DEFAULT_MIN_ATTEMPTS =
20
- DEFAULT_FAILURE_FUNC =
Proc.new { |successes, failures| abort "Aborting because too many failures. Successes: #{successes}. Failures: #{failures}" }
- DEFAULT_MAX_COUNT =
1000000
Instance Method Summary collapse
- #get_total ⇒ Object
- #inc_failures ⇒ Object
- #inc_successes ⇒ Object
-
#initialize(opts = {}) ⇒ Agent
constructor
A new instance of Agent.
- #reset! ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Agent
Returns a new instance of Agent.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/self_destruct.rb', line 11 def initialize(opts = {}) @success_count = 0 @failure_count = 0 @start_time = nil @ratio_threshold = opts[:ratio_threshold] || DEFAULT_RATIO_THRESHOLD @grace_period = opts[:grace_period] || DEFAULT_GRACE_PERIOD @min_attempts = opts[:min_attempts] || DEFAULT_MIN_ATTEMPTS @failure_func = opts[:failure_func] || DEFAULT_FAILURE_FUNC @max_count = opts[:max_count] || DEFAULT_MAX_COUNT end |
Instance Method Details
#get_total ⇒ Object
38 39 40 |
# File 'lib/self_destruct.rb', line 38 def get_total @success_count + @failure_count end |
#inc_failures ⇒ Object
27 28 29 30 |
# File 'lib/self_destruct.rb', line 27 def inc_failures @failure_count += 1 check_ratio! end |
#inc_successes ⇒ Object
22 23 24 25 |
# File 'lib/self_destruct.rb', line 22 def inc_successes @success_count += 1 check_ratio! end |
#reset! ⇒ Object
32 33 34 35 36 |
# File 'lib/self_destruct.rb', line 32 def reset! @success_count = 0 @failure_count = 0 @start_time = nil end |