Sha256: 3cf7d9a3055881efb7fc51b9a28e3c0027e1b71215bb3cf35ab3bfc9cc19187d

Contents?: true

Size: 1.32 KB

Versions: 21

Compression:

Stored size: 1.32 KB

Contents

namespace :retry_middleware do
  desc "Test retry middleware"
  task test: :environment do
    config = ::Hubspot::Crm::Contacts::Configuration.new do |config|
      config.access_token = ENV['access_token']
      config.error_handler = {
        429 => {
          max_retries: 2,
          seconds_delay: 10,
          retry_block: -> () { puts 'API returned 429 Status Code. Sleeping...' }
        },
      }
    end
    api_client = ::Hubspot::Crm::Contacts::ApiClient.new(config)
    batch_api = ::Hubspot::Crm::Contacts::BatchApi.new(api_client)

    contacts = (1..3).map do |i|
      ::Hubspot::Crm::Contacts::SimplePublicObjectInput.new(
        properties: { email: "retry_middleware_app#{i}@hubspot.com" }
      )
    end

    Parallel.map((1..10).to_a, in_processes: 10) do |process|
      loop do
        contacts_object = ::Hubspot::Crm::Contacts::BatchInputSimplePublicObjectInput.new(
          inputs: contacts
        )
        response = batch_api.create_batch(body: contacts_object, auth_names: 'oauth2')
        ids_object = ::Hubspot::Crm::Contacts::BatchInputSimplePublicObjectId.new(
          inputs: response.results.map(&:id)
        )
        batch_api.archive_batch(body: ids_object , auth_names: 'oauth2')
        puts "##{process} :: #{Time.current} :: Created and deleted batch of contacts."
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-8.0.1 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-8.0.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-7.3.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-7.2.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-7.1.1 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-7.1.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-7.0.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-6.0.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-5.0.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-4.0.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-3.3.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-3.2.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-3.1.1 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-3.1.0.pre.beta sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-3.0.0.pre.beta sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-2.3.2 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-2.3.1 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-2.2.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake
hubspot-api-client-2.1.0 sample-apps/retry-middleware-sample-app/lib/tasks/retry_middleware.rake