Module: Graphiti::Rails::RakeHelpers
- Extended by:
- TestHelpers
- Defined in:
- lib/graphiti/rails/rake_helpers.rb
Overview
Rake's namespace takes a block, and a block does not open a new definee,
so helpers defined inside one are defined on Object and turn up in every
request spec in the host app. They live here to stay off that namespace.
Class Method Summary collapse
-
.connection_pool_advisory ⇒ Object
The pool and RAILS_MAX_THREADS are read from this environment, and production may size both differently.
- .make_request(path, debug = false) ⇒ Object
-
.session ⇒ Object
::Rails throughout, because bare Rails resolves to Graphiti::Rails here.
- .setup_rails! ⇒ Object
Methods included from TestHelpers
handle_request_exceptions, handle_request_exceptions?
Class Method Details
.connection_pool_advisory ⇒ Object
The pool and RAILS_MAX_THREADS are read from this environment, and production may size both differently.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/graphiti/rails/rake_helpers.rb', line 25 def connection_pool_advisory return unless defined?(ActiveRecord::Base) pool = ActiveRecord::Base.connection_db_config.pool threads = ENV.fetch("RAILS_MAX_THREADS", 5).to_i sideload_threads = Graphiti.config.concurrency_max_threads needed = threads + sideload_threads + 1 return if pool.nil? || pool >= needed "WARNING database.yml pool is #{pool} in this environment. With concurrency on (the production default), " \ "each sideload holds its own connection, so pool should be at least " \ "web threads (#{threads}) + concurrency_max_threads (#{sideload_threads}) + 1 = #{needed}. " \ "If production sizes these differently, check the numbers there. " \ "See graphiti.dev/concepts/resources#concurrency-pool-sizing." end |
.make_request(path, debug = false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/graphiti/rails/rake_helpers.rb', line 41 def make_request(path, debug = false) if path.split("/").length == 2 path = "#{ApplicationResource.endpoint_namespace}#{path}" end path << if path.include?("?") "&cache=bust" else "?cache=bust" end path = "#{path}&debug=true" if debug handle_request_exceptions do headers = {Authorization: ENV["AUTHORIZATION_HEADER"]}.compact session.get(path.to_s, headers: headers) end JSON.parse(session.response.body) end |
.session ⇒ Object
::Rails throughout, because bare Rails resolves to Graphiti::Rails here.
14 15 16 |
# File 'lib/graphiti/rails/rake_helpers.rb', line 14 def session @session ||= ActionDispatch::Integration::Session.new(::Rails.application) end |
.setup_rails! ⇒ Object
18 19 20 21 22 |
# File 'lib/graphiti/rails/rake_helpers.rb', line 18 def setup_rails! ::Rails.application.eager_load! ::Rails.application.config.cache_classes = true ::Rails.application.config.action_controller.perform_caching = false end |