Class: ComplyanceSDK::Retry::RetryManager
- Inherits:
-
Object
- Object
- ComplyanceSDK::Retry::RetryManager
- Defined in:
- lib/complyance_sdk/retry/retry_manager.rb
Overview
Manager class that coordinates retry strategies and circuit breakers
Instance Method Summary collapse
-
#circuit_breaker_status(operation_name) ⇒ Hash
Get circuit breaker status for an operation.
-
#execute(operation_name, context = {}) { ... } ⇒ Object
Execute a block with retry logic and circuit breaker protection.
-
#execute_async(request_data, job_type: :active_job, callback_url: nil, callback_headers: {}) ⇒ String, Object
Execute a block asynchronously using background jobs.
-
#initialize(config, redis_config = {}) ⇒ RetryManager
constructor
Initialize a new retry manager.
-
#reset_all_circuit_breakers ⇒ Object
Reset all circuit breakers.
-
#reset_circuit_breaker(operation_name) ⇒ Object
Reset a circuit breaker.
Constructor Details
#initialize(config, redis_config = {}) ⇒ RetryManager
Initialize a new retry manager
14 15 16 17 18 |
# File 'lib/complyance_sdk/retry/retry_manager.rb', line 14 def initialize(config, redis_config = {}) @config = config @redis_config = redis_config @circuit_breakers = {} end |
Instance Method Details
#circuit_breaker_status(operation_name) ⇒ Hash
Get circuit breaker status for an operation
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/complyance_sdk/retry/retry_manager.rb', line 72 def circuit_breaker_status(operation_name) circuit_breaker = get_circuit_breaker(operation_name) { name: operation_name, state: circuit_breaker.current_state, failure_count: circuit_breaker.failure_count, last_failure_time: circuit_breaker.last_failure_time, disabled: circuit_breaker.disabled? } end |
#execute(operation_name, context = {}) { ... } ⇒ Object
Execute a block with retry logic and circuit breaker protection
26 27 28 29 30 31 32 33 |
# File 'lib/complyance_sdk/retry/retry_manager.rb', line 26 def execute(operation_name, context = {}) circuit_breaker = get_circuit_breaker(operation_name) retry_strategy = RetryStrategy.new(@config.retry_config, circuit_breaker) retry_strategy.execute(context.merge(operation: operation_name)) do yield end end |
#execute_async(request_data, job_type: :active_job, callback_url: nil, callback_headers: {}) ⇒ String, Object
Execute a block asynchronously using background jobs
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/complyance_sdk/retry/retry_manager.rb', line 42 def execute_async(request_data, job_type: :active_job, callback_url: nil, callback_headers: {}) case job_type when :active_job if defined?(ActiveJob) require_relative "../jobs/process_document_job" job = Jobs::ProcessDocumentJob.perform_later(request_data, callback_url, callback_headers) job.job_id else raise ComplyanceSDK::Exceptions::ConfigurationError.new( "ActiveJob is not available. Please add 'activejob' to your Gemfile." ) end when :sidekiq if defined?(Sidekiq) require_relative "../jobs/sidekiq_job" Jobs::SidekiqJob.perform_async(request_data, callback_url, callback_headers) else raise ComplyanceSDK::Exceptions::ConfigurationError.new( "Sidekiq is not available. Please add 'sidekiq' to your Gemfile." ) end else raise ArgumentError, "Invalid job_type: #{job_type}. Must be :active_job or :sidekiq" end end |
#reset_all_circuit_breakers ⇒ Object
Reset all circuit breakers
93 94 95 |
# File 'lib/complyance_sdk/retry/retry_manager.rb', line 93 def reset_all_circuit_breakers @circuit_breakers.each_value(&:reset!) end |
#reset_circuit_breaker(operation_name) ⇒ Object
Reset a circuit breaker
87 88 89 90 |
# File 'lib/complyance_sdk/retry/retry_manager.rb', line 87 def reset_circuit_breaker(operation_name) circuit_breaker = get_circuit_breaker(operation_name) circuit_breaker.reset! end |