client.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer
  3. class Unit
  4. module Zendesk
  5. class Client < Sequencer::Unit::Common::Provider::Fallback
  6. provides :client
  7. private
  8. def client
  9. require 'zendesk_api' # Only load this gem when it is really used.
  10. ZendeskAPI::Client.new do |config|
  11. config.url = Setting.get('import_zendesk_endpoint')
  12. # Basic / Token Authentication
  13. config.username = Setting.get('import_zendesk_endpoint_username')
  14. config.token = Setting.get('import_zendesk_endpoint_key')
  15. # when hitting the rate limit, sleep automatically,
  16. # then retry the request.
  17. config.retry = true
  18. # Activate the retry also for exception, e.g. for Faraday::SSLError.
  19. config.retry_on_exception = true
  20. # disable cache to avoid unneeded memory consumption
  21. # since we are using each object only once
  22. # Inspired by: https://medium.com/swiftype-engineering/using-jmat-to-find-analyze-memory-in-jruby-1c4196c1ec72
  23. config.cache = false
  24. # increase timeouts to avoid network issues.
  25. config.client_options = {
  26. request: {
  27. open_timeout: 20, # default is 10
  28. timeout: 120, # default is 60
  29. },
  30. }
  31. end
  32. end
  33. end
  34. end
  35. end
  36. end