fly-ruby 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +0 -2
- data/Gemfile +1 -0
- data/lib/fly-ruby/configuration.rb +14 -8
- data/lib/fly-ruby/railtie.rb +3 -15
- data/lib/fly-ruby/version.rb +1 -1
- data/lib/fly-ruby.rb +5 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc19c3c6ff9a2dd0cfdc09640fa1bfd3a4eeeb60ff9be84774cdda50b8956faf
|
4
|
+
data.tar.gz: 44646945289997faed2261594766a55ae2c343f272c7aa85bedb116cb869037a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17454e355c0f56c595fc3f01548b9bad679545d6d4da74ae20f813a441c878db6234ddee67cb67e2327449d18de6339accd9e14277103b036d1a7e9a767196ef
|
7
|
+
data.tar.gz: 065b6d3473c02437a1123751524a4812c8bc7bb5b1da0736f095abdf5c9b4437a13709b5e5a63b0fd8d241c52160cbe20a99e8117fc3e0a164f4cf665d3978d1
|
data/.github/workflows/test.yml
CHANGED
data/Gemfile
CHANGED
@@ -62,12 +62,12 @@ module Fly
|
|
62
62
|
|
63
63
|
def database_uri
|
64
64
|
@database_uri ||= URI.parse(database_url)
|
65
|
-
@database_uri
|
66
65
|
end
|
67
66
|
|
68
67
|
def regional_database_url
|
69
68
|
uri = database_uri.dup
|
70
69
|
uri.host = regional_database_host
|
70
|
+
uri.port = regional_database_port
|
71
71
|
uri.to_s
|
72
72
|
end
|
73
73
|
|
@@ -75,13 +75,15 @@ module Fly
|
|
75
75
|
"#{current_region}.#{database_uri.hostname}"
|
76
76
|
end
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
def regional_database_port
|
79
|
+
port = if in_secondary_region?
|
80
|
+
case database_uri.scheme
|
81
|
+
when "postgres"
|
82
|
+
5433
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
port || database_uri.port
|
85
87
|
end
|
86
88
|
|
87
89
|
def redis_uri
|
@@ -103,6 +105,10 @@ module Fly
|
|
103
105
|
database_url && primary_region && current_region && web?
|
104
106
|
end
|
105
107
|
|
108
|
+
def hijack_database_connection?
|
109
|
+
in_secondary_region? && !database_uri.scheme.start_with?("sqlite")
|
110
|
+
end
|
111
|
+
|
106
112
|
def in_secondary_region?
|
107
113
|
primary_region && primary_region != current_region
|
108
114
|
end
|
data/lib/fly-ruby/railtie.rb
CHANGED
@@ -1,19 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Fly::Railtie < Rails::Railtie
|
4
|
-
|
5
|
-
ActiveSupport::Reloader.to_prepare do
|
6
|
-
# If we already have a database connection when this initializer runs,
|
7
|
-
# we should reconnect to the region-local database. This may need some additional
|
8
|
-
# hooks for forking servers to work correctly.
|
9
|
-
if defined?(ActiveRecord)
|
10
|
-
config = ActiveRecord::Base.connection_db_config.configuration_hash
|
11
|
-
ActiveRecord::Base.establish_connection(config.symbolize_keys.merge(Fly.configuration.regional_database_config))
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
initializer("fly.regional_database") do |app|
|
4
|
+
initializer("fly.regional_database", before: "active_record.initialize_database") do |app|
|
17
5
|
# Insert the request middleware high in the stack, but after static file delivery
|
18
6
|
app.config.middleware.insert_after ActionDispatch::Executor, Fly::Headers if Fly.configuration.web?
|
19
7
|
|
@@ -22,8 +10,8 @@ class Fly::Railtie < Rails::Railtie
|
|
22
10
|
# Insert the database exception handler at the bottom of the stack to take priority over other exception handlers
|
23
11
|
app.config.middleware.use Fly::RegionalDatabase::DbExceptionHandlerMiddleware
|
24
12
|
|
25
|
-
if Fly.configuration.
|
26
|
-
|
13
|
+
if Fly.configuration.hijack_database_connection?
|
14
|
+
ENV["DATABASE_URL"] = Fly.configuration.regional_database_url
|
27
15
|
end
|
28
16
|
elsif Fly.configuration.web?
|
29
17
|
puts "Warning: DATABASE_URL, PRIMARY_REGION and FLY_REGION must be set to activate the fly-ruby middleware. Middleware not loaded."
|
data/lib/fly-ruby/version.rb
CHANGED
data/lib/fly-ruby.rb
CHANGED
@@ -22,16 +22,14 @@ module Fly
|
|
22
22
|
end
|
23
23
|
|
24
24
|
class Instance
|
25
|
-
|
25
|
+
attr_writer :configuration
|
26
26
|
|
27
|
-
def
|
28
|
-
|
27
|
+
def configuration
|
28
|
+
@configuration ||= Fly::Configuration.new
|
29
29
|
end
|
30
30
|
|
31
|
-
def configure
|
32
|
-
configuration
|
33
|
-
yield(configuration) if block_given?
|
34
|
-
self.configuration = configuration
|
31
|
+
def configure(&block)
|
32
|
+
configuration.tap(&block)
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|