Class: ShopifyTransporter::Exporters::Magento::Soap
- Inherits:
-
Object
- Object
- ShopifyTransporter::Exporters::Magento::Soap
- Defined in:
- lib/shopify_transporter/exporters/magento/soap.rb
Constant Summary collapse
- RETRY_SLEEP_TIME =
0.1
- MAX_RETRIES =
4
Instance Method Summary collapse
- #call(method, params) ⇒ Object
- #call_in_batches(method:, params: {}, batch_index_column:) ⇒ Object
-
#initialize(hostname: '', username: '', api_key: '', batch_config:) ⇒ Soap
constructor
A new instance of Soap.
Constructor Details
#initialize(hostname: '', username: '', api_key: '', batch_config:) ⇒ Soap
Returns a new instance of Soap.
13 14 15 16 17 18 |
# File 'lib/shopify_transporter/exporters/magento/soap.rb', line 13 def initialize(hostname: '', username: '', api_key: '', batch_config:) @hostname = hostname @username = username @api_key = api_key @batch_config = batch_config end |
Instance Method Details
#call(method, params) ⇒ Object
20 21 22 |
# File 'lib/shopify_transporter/exporters/magento/soap.rb', line 20 def call(method, params) call_with_retries(method, params) end |
#call_in_batches(method:, params: {}, batch_index_column:) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/shopify_transporter/exporters/magento/soap.rb', line 24 def call_in_batches(method:, params: {}, batch_index_column:) current_id = @batch_config['first_id'] max_id = @batch_config['last_id'] batch_size = @batch_config['batch_size'] Enumerator.new do |enumerator| while current_id <= max_id end_of_range = current_id + batch_size - 1 end_of_range = max_id if end_of_range >= max_id $stderr.puts "Processing batch: #{current_id}..#{end_of_range}" begin enumerator << call( method, params.merge(batching_filter(current_id, end_of_range, batch_index_column)), ) rescue Savon::Error => e output = 'Skipping batch: '\ "#{current_id}..#{end_of_range} after #{MAX_RETRIES} retries because of an error." $stderr.puts output $stderr.puts 'The exact error was:' $stderr.puts "#{e.class}: " $stderr.puts e. end current_id += batch_size end end end |