Sha256: a4168df1d5b29ccdbd66d086ae814d05db261f42ecbc2b97566b30ecfbb357b7

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

module BridgeCache::Jobs
  class ImportCheck < ActiveJob::Base
    queue_as :default
    include BridgeCache::Utils::WorkerHelper

    ATTEMPTS_THRESHOLD = 30

    def perform(bridge_base_url, bridge_api_key, bridge_api_secret, models, attempts, chain = [], global_options = {})
      remote_data = BridgeBlueprint::RemoteData.new(bridge_base_url, bridge_api_key, bridge_api_secret)
      if attempts > ATTEMPTS_THRESHOLD
        Rails.logger.fatal("Bridge data dump failed to download after #{(ATTEMPTS_THRESHOLD * 30) / 60} minutes")
      elsif remote_data.status == BridgeBlueprint::Constants::STATUS_COMPLETE
        BridgeCache::Jobs::ImportData.set(queue: self.queue_name).perform_later(bridge_base_url, bridge_api_key, bridge_api_secret, models, chain, global_options)
      elsif remote_data.status == BridgeBlueprint::Constants::STATUS_PENDING
        BridgeCache::Jobs::ImportCheck.set(queue: self.queue_name, wait: 30.seconds).perform_later(bridge_base_url, bridge_api_key, bridge_api_secret, models, attempts + 1, chain, global_options)
      elsif remote_data.status == BridgeBlueprint::Constants::STATUS_FAILED || remote_data.status == BridgeBlueprint::Constants::STATUS_NOT_FOUND
        raise 'Bridge data dump download failed'
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bridge_cache-0.2.8 app/lib/bridge_cache/jobs/import_check.rb
bridge_cache-0.2.7 app/lib/bridge_cache/jobs/import_check.rb
bridge_cache-0.2.6 app/lib/bridge_cache/jobs/import_check.rb
bridge_cache-0.2.5 app/lib/bridge_cache/jobs/import_check.rb
bridge_cache-0.2.4 app/lib/bridge_cache/jobs/import_check.rb
bridge_cache-0.2.3 app/lib/bridge_cache/jobs/import_check.rb
bridge_cache-0.2.2 app/lib/bridge_cache/jobs/import_check.rb
bridge_cache-0.2.1 app/lib/bridge_cache/jobs/import_check.rb