Sha256: d192530eb632a313c594d805fc42dc0bcef30ec5f1306133b046965c21baed58

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

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

      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|
            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
    end
  end
end
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bridge_cache-0.3.23 app/lib/bridge_cache/jobs/import_data.rb
bridge_cache-0.3.22 app/lib/bridge_cache/jobs/import_data.rb
bridge_cache-0.3.21 app/lib/bridge_cache/jobs/import_data.rb
bridge_cache-0.3.20 app/lib/bridge_cache/jobs/import_data.rb