8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/lib/bridge_cache/jobs/import_data.rb', line 8
def perform(account_settings, chain = [])
account_settings = account_settings.with_indifferent_access
remote_data = BridgeBlueprint::RemoteData.new(account_settings[:url], account_settings[:api_key],
account_settings[:api_secret])
Dir.mktmpdir do |dir|
path = "#{dir}/data_dump"
remote_data.store_file(path)
import = BridgeBlueprint::DataDump.new(path)
models = account_settings[:models] || BridgeCache.resolved_models(account_settings[:is_subaccount])
models.each do |model|
model = model.singularize
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
|