chewy.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. enabled = ENV['ES_ENABLED'] == 'true'
  2. host = ENV.fetch('ES_HOST') { 'localhost' }
  3. port = ENV.fetch('ES_PORT') { 9200 }
  4. user = ENV.fetch('ES_USER') { nil }
  5. password = ENV.fetch('ES_PASS') { nil }
  6. fallback_prefix = ENV.fetch('REDIS_NAMESPACE') { nil }
  7. prefix = ENV.fetch('ES_PREFIX') { fallback_prefix }
  8. Chewy.settings = {
  9. host: "#{host}:#{port}",
  10. prefix: prefix,
  11. enabled: enabled,
  12. journal: false,
  13. user: user,
  14. password: password,
  15. sidekiq: { queue: 'pull' },
  16. }
  17. # We use our own async strategy even outside the request-response
  18. # cycle, which takes care of checking if Elasticsearch is enabled
  19. # or not. However, mind that for the Rails console, the :urgent
  20. # strategy is set automatically with no way to override it.
  21. Chewy.root_strategy = :custom_sidekiq
  22. Chewy.request_strategy = :custom_sidekiq
  23. Chewy.use_after_commit_callbacks = false
  24. module Chewy
  25. class << self
  26. def enabled?
  27. settings[:enabled]
  28. end
  29. end
  30. end
  31. # Elasticsearch uses Faraday internally. Faraday interprets the
  32. # http_proxy env variable by default which leads to issues when
  33. # Mastodon is run with hidden services enabled, because
  34. # Elasticsearch is *not* supposed to be accessed through a proxy
  35. Faraday.ignore_env_proxy = true