Sha256: 7ace192f8db7b8dad0930ef617c7018575a2bc762ec9f00b461894c16fee5708

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

# rubocop:disable Metrics/AbcSize,Metrics/MethodLength
module BridgeCache
  module Jobs
    class ImportCheck < ActiveJob::Base
      queue_as :default
      include BridgeCache::Utils::WorkerHelper

      def max_import_attempts
        ENV.fetch('BRIDGE_CACHE_MAX_IMPORT_ATTEMPTS', 30)
      end

      def remote_data
        @remote_data ||= BridgeBlueprint::RemoteData.new(@account_settings[:url], @account_settings[:api_key],
                                                         @account_settings[:api_secret])
      end

      def perform(account_settings, attempts, chain = [], retries = 0)
        @account_settings = account_settings.with_indifferent_access

        if attempts > max_import_attempts
          Rails.logger.fatal("Bridge data dump failed to download after #{(max_import_attempts * 30) / 60} minutes")
        elsif remote_data.status == BridgeBlueprint::Constants::STATUS_COMPLETE
          BridgeCache::Jobs::ImportData.set(queue: queue_name).perform_later(@account_settings, chain)
        elsif remote_data.status == BridgeBlueprint::Constants::STATUS_PENDING
          BridgeCache::Jobs::ImportCheck.set(queue: queue_name, wait: 30.seconds).perform_later(@account_settings,
                                                                                                attempts + 1, chain)
        elsif remote_data.status == BridgeBlueprint::Constants::STATUS_FAILED ||
              remote_data.status == BridgeBlueprint::Constants::STATUS_NOT_FOUND

          raise 'Bridge data dump download failed' if retries < 1

          BridgeCache::Jobs::ImportStart.set(queue: queue_name).perform_later(@account_settings, chain, retries - 1)
        end
      end
    end
  end
end
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bridge_cache-0.3.21 app/lib/bridge_cache/jobs/import_check.rb