Class: BridgeCache::Jobs::ImportData

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

Instance Method Summary collapse

Methods included from Utils::WorkerHelper

invoke_next

Instance Method Details

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/lib/bridge_cache/jobs/import_data.rb', line 8

def perform(, chain = [])
   = .with_indifferent_access
  remote_data = BridgeBlueprint::RemoteData.new([:url], [:api_key],
                                                [:api_secret])
  Dir.mktmpdir do |dir|
    path = "#{dir}/data_dump"
    remote_data.store_file(path)
    import = BridgeBlueprint::DataDump.new(path)
    models = [:models] || BridgeCache.resolved_models([:is_subaccount])

    models.each do |model|
      ids = []
      ids << BridgeCache::Plugins::CSVDump.bulk_import(import, model)
      BridgeCache::Jobs::CleanupJob.set(queue: queue_name).perform_later(model, ids)
    end
  end

  BridgeCache::Utils::WorkerHelper.invoke_next(chain)
end