Sha256: d0ed9ab26bf6eb3c71d6dec720fcf49e14e482a71b2bf90c5d8e68395aee6125
Contents?: true
Size: 1.95 KB
Versions: 2
Compression:
Stored size: 1.95 KB
Contents
# frozen_string_literal: true module Mihari # # Yet another base service class for Analyzer, Emitter and Enricher # class Actor include Dry::Monads[:result, :try] include Mixins::Configurable include Mixins::Retriable # @return [Hash] attr_reader :options # # @param [Hash, nil] options # def initialize(options: nil) super() @options = options || {} end # # @return [Integer] # def retry_interval options[:retry_interval] || Mihari.config.retry_interval end # # @return [Boolean] # def retry_exponential_backoff options[:retry_exponential_backoff] || Mihari.config.retry_exponential_backoff end # # @return [Integer] # def retry_times options[:retry_times] || Mihari.config.retry_times end # # @return [Integer, nil] # def timeout options[:timeout] end def validate_configuration! return if configured? joined = configuration_keys.join(", ") be = (configuration_keys.length > 1) ? "are" : "is" message = "#{self.class.class_key} is not configured correctly. #{joined} #{be} missing." raise ConfigurationError, message end def call(*args, **kwargs) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end def result(...) Try[StandardError] do retry_on_error(times: retry_times, interval: retry_interval, exponential_backoff: retry_exponential_backoff) do call(...) end end.to_result end class << self # # @return [String] # def class_key to_s.split("::").last.downcase end # # @return [Array<String>, nil] # def class_key_aliases nil end # # @return [Array<String>] # def class_keys ([class_key] + [class_key_aliases]).flatten.compact.map(&:downcase) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mihari-6.3.0 | lib/mihari/actor.rb |
mihari-6.2.0 | lib/mihari/actor.rb |