s3_relay 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +3 -19
- data/app/assets/javascripts/s3_relay.coffee +4 -4
- data/app/controllers/s3_relay/uploads_controller.rb +8 -2
- data/app/models/s3_relay/upload.rb +1 -1
- data/db/migrate/20141009000804_create_s3_relay_uploads.rb +1 -1
- data/lib/s3_relay/base.rb +1 -1
- data/lib/s3_relay/engine.rb +1 -1
- data/lib/s3_relay/private_url.rb +1 -1
- data/lib/s3_relay/version.rb +1 -1
- data/test/controllers/s3_relay/uploads_controller_test.rb +28 -22
- data/test/dummy/{README.rdoc → README.md} +1 -5
- data/test/dummy/Rakefile +1 -1
- data/test/dummy/app/assets/config/manifest.js +3 -0
- data/test/dummy/app/assets/javascripts/application.js +6 -4
- data/test/dummy/app/assets/javascripts/cable.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +5 -5
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +0 -2
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/product.rb +1 -1
- data/test/dummy/app/views/layouts/application.html.erb +9 -9
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/rails +6 -1
- data/test/dummy/bin/rake +5 -0
- data/test/dummy/bin/setup +38 -0
- data/test/dummy/bin/spring +17 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config.ru +2 -1
- data/test/dummy/config/application.rb +7 -11
- data/test/dummy/config/boot.rb +2 -4
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/environment.rb +1 -1
- data/test/dummy/config/environments/development.rb +24 -7
- data/test/dummy/config/environments/production.rb +36 -23
- data/test/dummy/config/environments/test.rb +6 -3
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +8 -2
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -1
- data/test/dummy/config/initializers/wrap_parameters.rb +2 -2
- data/test/dummy/config/locales/en.yml +10 -0
- data/test/dummy/config/puma.rb +56 -0
- data/test/dummy/config/secrets.yml +15 -5
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/migrate/20141021002149_create_products.rb +1 -1
- data/test/dummy/db/schema.rb +13 -14
- data/test/dummy/db/seeds.rb +7 -0
- data/test/dummy/log/development.log +60 -20
- data/test/dummy/log/test.log +10958 -856
- data/test/dummy/package.json +5 -0
- data/test/dummy/public/404.html +6 -6
- data/test/dummy/public/422.html +6 -6
- data/test/dummy/public/500.html +6 -6
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/robots.txt +1 -0
- data/test/dummy/test/application_system_test_case.rb +5 -0
- data/test/dummy/test/test_helper.rb +9 -0
- data/test/factories/products.rb +2 -2
- data/test/factories/uploads.rb +14 -7
- data/test/helpers/s3_relay/uploads_helper_test.rb +7 -4
- data/test/lib/s3_relay/model_test.rb +15 -15
- data/test/lib/s3_relay/private_url_test.rb +1 -1
- data/test/lib/s3_relay/upload_presigner_test.rb +9 -9
- data/test/models/s3_relay/upload_test.rb +25 -24
- data/test/test_helper.rb +2 -4
- metadata +110 -72
- data/test/dummy/config/initializers/session_store.rb +0 -3
data/test/dummy/bin/rails
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
begin
|
3
|
+
load File.expand_path('../spring', __FILE__)
|
4
|
+
rescue LoadError => e
|
5
|
+
raise unless e.message.include?('spring')
|
6
|
+
end
|
7
|
+
APP_PATH = File.expand_path('../config/application', __dir__)
|
3
8
|
require_relative '../config/boot'
|
4
9
|
require 'rails/commands'
|
data/test/dummy/bin/rake
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
require 'fileutils'
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
chdir APP_ROOT do
|
14
|
+
# This script is a starting point to setup your application.
|
15
|
+
# Add necessary setup steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system! 'gem install bundler --conservative'
|
19
|
+
system('bundle check') || system!('bundle install')
|
20
|
+
|
21
|
+
# Install JavaScript dependencies if using Yarn
|
22
|
+
# system('bin/yarn')
|
23
|
+
|
24
|
+
|
25
|
+
# puts "\n== Copying sample files =="
|
26
|
+
# unless File.exist?('config/database.yml')
|
27
|
+
# cp 'config/database.yml.sample', 'config/database.yml'
|
28
|
+
# end
|
29
|
+
|
30
|
+
puts "\n== Preparing database =="
|
31
|
+
system! 'bin/rails db:setup'
|
32
|
+
|
33
|
+
puts "\n== Removing old logs and tempfiles =="
|
34
|
+
system! 'bin/rails log:clear tmp:clear'
|
35
|
+
|
36
|
+
puts "\n== Restarting application server =="
|
37
|
+
system! 'bin/rails restart'
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This file loads spring without using Bundler, in order to be fast.
|
4
|
+
# It gets overwritten when you run the `spring binstub` command.
|
5
|
+
|
6
|
+
unless defined?(Spring)
|
7
|
+
require 'rubygems'
|
8
|
+
require 'bundler'
|
9
|
+
|
10
|
+
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
|
11
|
+
spring = lockfile.specs.detect { |spec| spec.name == "spring" }
|
12
|
+
if spring
|
13
|
+
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
|
14
|
+
gem 'spring', spring.version
|
15
|
+
require 'spring/binstub'
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
require 'fileutils'
|
4
|
+
include FileUtils
|
5
|
+
|
6
|
+
# path to your application root.
|
7
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
8
|
+
|
9
|
+
def system!(*args)
|
10
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
11
|
+
end
|
12
|
+
|
13
|
+
chdir APP_ROOT do
|
14
|
+
# This script is a way to update your development environment automatically.
|
15
|
+
# Add necessary update steps to this file.
|
16
|
+
|
17
|
+
puts '== Installing dependencies =='
|
18
|
+
system! 'gem install bundler --conservative'
|
19
|
+
system('bundle check') || system!('bundle install')
|
20
|
+
|
21
|
+
puts "\n== Updating database =="
|
22
|
+
system! 'bin/rails db:migrate'
|
23
|
+
|
24
|
+
puts "\n== Removing old logs and tempfiles =="
|
25
|
+
system! 'bin/rails log:clear tmp:clear'
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system! 'bin/rails restart'
|
29
|
+
end
|
data/test/dummy/bin/yarn
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
VENDOR_PATH = File.expand_path('..', __dir__)
|
3
|
+
Dir.chdir(VENDOR_PATH) do
|
4
|
+
begin
|
5
|
+
exec "yarnpkg #{ARGV.join(" ")}"
|
6
|
+
rescue Errno::ENOENT
|
7
|
+
$stderr.puts "Yarn executable was not detected in the system."
|
8
|
+
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
end
|
data/test/dummy/config.ru
CHANGED
@@ -1,23 +1,19 @@
|
|
1
|
-
|
1
|
+
require_relative 'boot'
|
2
2
|
|
3
3
|
require 'rails/all'
|
4
|
+
require 's3_relay'
|
4
5
|
|
6
|
+
# Require the gems listed in Gemfile, including any gems
|
7
|
+
# you've limited to :test, :development, or :production.
|
5
8
|
Bundler.require(*Rails.groups)
|
6
|
-
require "s3_relay"
|
7
9
|
|
8
10
|
module Dummy
|
9
11
|
class Application < Rails::Application
|
12
|
+
# Initialize configuration defaults for originally generated Rails version.
|
13
|
+
config.load_defaults 5.1
|
14
|
+
|
10
15
|
# Settings in config/environments/* take precedence over those specified here.
|
11
16
|
# Application configuration should go into files in config/initializers
|
12
17
|
# -- all .rb files in that directory are automatically loaded.
|
13
|
-
|
14
|
-
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
-
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
-
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
-
|
18
|
-
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
-
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
-
# config.i18n.default_locale = :de
|
21
18
|
end
|
22
19
|
end
|
23
|
-
|
data/test/dummy/config/boot.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
|
1
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
3
2
|
|
4
|
-
require 'bundler/setup'
|
5
|
-
$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
|
3
|
+
require 'bundler/setup' # Set up gems listed in the Gemfile.
|
@@ -9,13 +9,28 @@ Rails.application.configure do
|
|
9
9
|
# Do not eager load code on boot.
|
10
10
|
config.eager_load = false
|
11
11
|
|
12
|
-
# Show full error reports
|
13
|
-
config.consider_all_requests_local
|
14
|
-
|
12
|
+
# Show full error reports.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
|
15
|
+
# Enable/disable caching. By default caching is disabled.
|
16
|
+
if Rails.root.join('tmp/caching-dev.txt').exist?
|
17
|
+
config.action_controller.perform_caching = true
|
18
|
+
|
19
|
+
config.cache_store = :memory_store
|
20
|
+
config.public_file_server.headers = {
|
21
|
+
'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}"
|
22
|
+
}
|
23
|
+
else
|
24
|
+
config.action_controller.perform_caching = false
|
25
|
+
|
26
|
+
config.cache_store = :null_store
|
27
|
+
end
|
15
28
|
|
16
29
|
# Don't care if the mailer can't send.
|
17
30
|
config.action_mailer.raise_delivery_errors = false
|
18
31
|
|
32
|
+
config.action_mailer.perform_caching = false
|
33
|
+
|
19
34
|
# Print deprecation notices to the Rails logger.
|
20
35
|
config.active_support.deprecation = :log
|
21
36
|
|
@@ -27,11 +42,13 @@ Rails.application.configure do
|
|
27
42
|
# number of complex assets.
|
28
43
|
config.assets.debug = true
|
29
44
|
|
30
|
-
#
|
31
|
-
|
32
|
-
# Raises helpful error messages.
|
33
|
-
config.assets.raise_runtime_errors = true
|
45
|
+
# Suppress logger output for asset requests.
|
46
|
+
config.assets.quiet = true
|
34
47
|
|
35
48
|
# Raises error for missing translations
|
36
49
|
# config.action_view.raise_on_missing_translations = true
|
50
|
+
|
51
|
+
# Use an evented file watcher to asynchronously detect changes in source code,
|
52
|
+
# routes, locales, etc. This feature depends on the listen gem.
|
53
|
+
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
|
37
54
|
end
|
@@ -14,13 +14,14 @@ Rails.application.configure do
|
|
14
14
|
config.consider_all_requests_local = false
|
15
15
|
config.action_controller.perform_caching = true
|
16
16
|
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
|
17
|
+
# Attempt to read encrypted secrets from `config/secrets.yml.enc`.
|
18
|
+
# Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
|
19
|
+
# `config/secrets.yml.key`.
|
20
|
+
config.read_encrypted_secrets = true
|
21
21
|
|
22
|
-
# Disable
|
23
|
-
|
22
|
+
# Disable serving static files from the `/public` folder by default since
|
23
|
+
# Apache or NGINX already handles this.
|
24
|
+
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
24
25
|
|
25
26
|
# Compress JavaScripts and CSS.
|
26
27
|
config.assets.js_compressor = :uglifier
|
@@ -29,32 +30,37 @@ Rails.application.configure do
|
|
29
30
|
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
30
31
|
config.assets.compile = false
|
31
32
|
|
32
|
-
# Generate digests for assets URLs.
|
33
|
-
config.assets.digest = true
|
34
|
-
|
35
33
|
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
|
36
34
|
|
35
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
36
|
+
# config.action_controller.asset_host = 'http://assets.example.com'
|
37
|
+
|
37
38
|
# Specifies the header that your server uses for sending files.
|
38
|
-
# config.action_dispatch.x_sendfile_header =
|
39
|
-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for
|
39
|
+
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
40
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
41
|
+
|
42
|
+
# Mount Action Cable outside main process or domain
|
43
|
+
# config.action_cable.mount_path = nil
|
44
|
+
# config.action_cable.url = 'wss://example.com/cable'
|
45
|
+
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
|
40
46
|
|
41
47
|
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
42
48
|
# config.force_ssl = true
|
43
49
|
|
44
|
-
#
|
45
|
-
|
50
|
+
# Use the lowest log level to ensure availability of diagnostic information
|
51
|
+
# when problems arise.
|
52
|
+
config.log_level = :debug
|
46
53
|
|
47
54
|
# Prepend all log lines with the following tags.
|
48
|
-
|
49
|
-
|
50
|
-
# Use a different logger for distributed setups.
|
51
|
-
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
55
|
+
config.log_tags = [ :request_id ]
|
52
56
|
|
53
57
|
# Use a different cache store in production.
|
54
58
|
# config.cache_store = :mem_cache_store
|
55
59
|
|
56
|
-
#
|
57
|
-
# config.
|
60
|
+
# Use a real queuing backend for Active Job (and separate queues per environment)
|
61
|
+
# config.active_job.queue_adapter = :resque
|
62
|
+
# config.active_job.queue_name_prefix = "dummy_#{Rails.env}"
|
63
|
+
config.action_mailer.perform_caching = false
|
58
64
|
|
59
65
|
# Ignore bad email addresses and do not raise email delivery errors.
|
60
66
|
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
@@ -62,17 +68,24 @@ Rails.application.configure do
|
|
62
68
|
|
63
69
|
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
64
70
|
# the I18n.default_locale when a translation cannot be found).
|
65
|
-
config.i18n.fallbacks =
|
71
|
+
config.i18n.fallbacks = [I18n.default_locale]
|
66
72
|
|
67
73
|
# Send deprecation notices to registered listeners.
|
68
74
|
config.active_support.deprecation = :notify
|
69
75
|
|
70
|
-
# Disable automatic flushing of the log to improve performance.
|
71
|
-
# config.autoflush_log = false
|
72
|
-
|
73
76
|
# Use default logging formatter so that PID and timestamp are not suppressed.
|
74
77
|
config.log_formatter = ::Logger::Formatter.new
|
75
78
|
|
79
|
+
# Use a different logger for distributed setups.
|
80
|
+
# require 'syslog/logger'
|
81
|
+
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
82
|
+
|
83
|
+
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
84
|
+
logger = ActiveSupport::Logger.new(STDOUT)
|
85
|
+
logger.formatter = config.log_formatter
|
86
|
+
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
87
|
+
end
|
88
|
+
|
76
89
|
# Do not dump schema after migrations.
|
77
90
|
config.active_record.dump_schema_after_migration = false
|
78
91
|
end
|
@@ -12,9 +12,11 @@ Rails.application.configure do
|
|
12
12
|
# preloads Rails for running tests, you may have to set it to true.
|
13
13
|
config.eager_load = false
|
14
14
|
|
15
|
-
# Configure
|
16
|
-
config.
|
17
|
-
config.
|
15
|
+
# Configure public file server for tests with Cache-Control for performance.
|
16
|
+
config.public_file_server.enabled = true
|
17
|
+
config.public_file_server.headers = {
|
18
|
+
'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
|
19
|
+
}
|
18
20
|
|
19
21
|
# Show full error reports and disable caching.
|
20
22
|
config.consider_all_requests_local = true
|
@@ -25,6 +27,7 @@ Rails.application.configure do
|
|
25
27
|
|
26
28
|
# Disable request forgery protection in test environment.
|
27
29
|
config.action_controller.allow_forgery_protection = false
|
30
|
+
config.action_mailer.perform_caching = false
|
28
31
|
|
29
32
|
# Tell Action Mailer not to deliver emails to the real world.
|
30
33
|
# The :test delivery method accumulates sent emails in the
|
@@ -3,6 +3,12 @@
|
|
3
3
|
# Version of your assets, change this if you want to expire all your assets.
|
4
4
|
Rails.application.config.assets.version = '1.0'
|
5
5
|
|
6
|
+
# Add additional assets to the asset load path.
|
7
|
+
# Rails.application.config.assets.paths << Emoji.images_path
|
8
|
+
# Add Yarn node_modules folder to the asset load path.
|
9
|
+
Rails.application.config.assets.paths << Rails.root.join('node_modules')
|
10
|
+
|
6
11
|
# Precompile additional assets.
|
7
|
-
# application.js, application.css, and all non-JS/CSS in app/assets
|
8
|
-
#
|
12
|
+
# application.js, application.css, and all non-JS/CSS in the app/assets
|
13
|
+
# folder are already added.
|
14
|
+
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
|
@@ -1,3 +1,5 @@
|
|
1
1
|
# Be sure to restart your server when you modify this file.
|
2
2
|
|
3
|
-
|
3
|
+
# Specify a serializer for the signed and encrypted cookie jars.
|
4
|
+
# Valid options are :json, :marshal, and :hybrid.
|
5
|
+
Rails.application.config.action_dispatch.cookies_serializer = :json
|
@@ -5,10 +5,10 @@
|
|
5
5
|
|
6
6
|
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
7
|
ActiveSupport.on_load(:action_controller) do
|
8
|
-
wrap_parameters format: [:json]
|
8
|
+
wrap_parameters format: [:json]
|
9
9
|
end
|
10
10
|
|
11
11
|
# To enable root element in JSON for ActiveRecord objects.
|
12
12
|
# ActiveSupport.on_load(:active_record) do
|
13
|
-
#
|
13
|
+
# self.include_root_in_json = true
|
14
14
|
# end
|
@@ -16,6 +16,16 @@
|
|
16
16
|
#
|
17
17
|
# This would use the information in config/locales/es.yml.
|
18
18
|
#
|
19
|
+
# The following keys must be escaped otherwise they will not be retrieved by
|
20
|
+
# the default I18n backend:
|
21
|
+
#
|
22
|
+
# true, false, on, off, yes, no
|
23
|
+
#
|
24
|
+
# Instead, surround them with single quotes.
|
25
|
+
#
|
26
|
+
# en:
|
27
|
+
# 'true': 'foo'
|
28
|
+
#
|
19
29
|
# To learn more, please read the Rails Internationalization guide
|
20
30
|
# available at http://guides.rubyonrails.org/i18n.html.
|
21
31
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Puma can serve each request in a thread from an internal thread pool.
|
2
|
+
# The `threads` method setting takes two numbers: a minimum and maximum.
|
3
|
+
# Any libraries that use thread pools should be configured to match
|
4
|
+
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
5
|
+
# and maximum; this matches the default thread size of Active Record.
|
6
|
+
#
|
7
|
+
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
|
8
|
+
threads threads_count, threads_count
|
9
|
+
|
10
|
+
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
11
|
+
#
|
12
|
+
port ENV.fetch("PORT") { 3000 }
|
13
|
+
|
14
|
+
# Specifies the `environment` that Puma will run in.
|
15
|
+
#
|
16
|
+
environment ENV.fetch("RAILS_ENV") { "development" }
|
17
|
+
|
18
|
+
# Specifies the number of `workers` to boot in clustered mode.
|
19
|
+
# Workers are forked webserver processes. If using threads and workers together
|
20
|
+
# the concurrency of the application would be max `threads` * `workers`.
|
21
|
+
# Workers do not work on JRuby or Windows (both of which do not support
|
22
|
+
# processes).
|
23
|
+
#
|
24
|
+
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
|
25
|
+
|
26
|
+
# Use the `preload_app!` method when specifying a `workers` number.
|
27
|
+
# This directive tells Puma to first boot the application and load code
|
28
|
+
# before forking the application. This takes advantage of Copy On Write
|
29
|
+
# process behavior so workers use less memory. If you use this option
|
30
|
+
# you need to make sure to reconnect any threads in the `on_worker_boot`
|
31
|
+
# block.
|
32
|
+
#
|
33
|
+
# preload_app!
|
34
|
+
|
35
|
+
# If you are preloading your application and using Active Record, it's
|
36
|
+
# recommended that you close any connections to the database before workers
|
37
|
+
# are forked to prevent connection leakage.
|
38
|
+
#
|
39
|
+
# before_fork do
|
40
|
+
# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
|
41
|
+
# end
|
42
|
+
|
43
|
+
# The code in the `on_worker_boot` will be called if you are using
|
44
|
+
# clustered mode by specifying a number of `workers`. After each worker
|
45
|
+
# process is booted, this block will be run. If you are using the `preload_app!`
|
46
|
+
# option, you will want to use this block to reconnect to any threads
|
47
|
+
# or connections that may have been created at application boot, as Ruby
|
48
|
+
# cannot share connections between processes.
|
49
|
+
#
|
50
|
+
# on_worker_boot do
|
51
|
+
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
|
55
|
+
# Allow puma to be restarted by `rails restart` command.
|
56
|
+
plugin :tmp_restart
|