Class: BridgeCache::Jobs::ImportCheck

Inherits:
ActiveJob::Base
  • Object
show all
Includes:
Utils::WorkerHelper
Defined in:
app/lib/bridge_cache/jobs/import_check.rb

Constant Summary collapse

ATTEMPTS_THRESHOLD =
30

Instance Method Summary collapse

Methods included from Utils::WorkerHelper

invoke_next

Instance Method Details

#perform(account_settings, attempts, chain = []) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/lib/bridge_cache/jobs/import_check.rb', line 8

def perform(, attempts, chain = [])
   = .with_indifferent_access
  remote_data = BridgeBlueprint::RemoteData.new([:url], [:api_key], [: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: queue_name).perform_later(, chain)
  elsif remote_data.status == BridgeBlueprint::Constants::STATUS_PENDING
    BridgeCache::Jobs::ImportCheck.set(queue: queue_name, wait: 30.seconds).perform_later(, 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'
  end
end