Sha256: c28e659c9c980cb4ca76984855802fdd829ae1c78e3c4aade5b9c085f872e316

Contents?: true

Size: 730 Bytes

Versions: 21

Compression:

Stored size: 730 Bytes

Contents

class LeakyBucketWorker
  @queue = :rate_limits

  class << self
    def perform(emails, access_token)
      Resque.logger.info('Sleep 0.2 seconds to avoid 429 error')
      sleep(0.2)
      response = create_contacts(emails, access_token)
      remove_contacts(response.results.map(&:id), access_token)
    end

    private

    def create_contacts(emails, access_token)
      response = Services::Hubspot::Contacts::CreateBatch.new(emails, access_token).call
      Resque.logger.info("Created contacts: #{emails}")
      response
    end

    def remove_contacts(ids, access_token)
      Services::Hubspot::Contacts::ArchiveBatch.new(ids, access_token).call
      Resque.logger.info("Removed contacts: #{ids}")
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-8.0.1 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-8.0.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-7.3.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-7.2.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-7.1.1 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-7.1.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-7.0.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-6.0.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-5.0.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-4.0.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-3.3.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-3.2.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-3.1.1 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-3.1.0.pre.beta sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-3.0.0.pre.beta sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-2.3.2 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-2.3.1 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-2.2.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb
hubspot-api-client-2.1.0 sample-apps/leaky-bucket-app/app/workers/leaky_bucket_worker.rb