fly-ruby 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dacb7a202a7a167f2ef451373f29893ca4efe7c0a46e60aeb4d958883a6cd3ec
4
- data.tar.gz: d650c2d9459908dc81f5bdf8f72f6744c097b5f40de20fc7c339b64b96797361
3
+ metadata.gz: 506556ce79da83a817f5a6a56b336328912730ace3fb26d10ed0d7e97f971abc
4
+ data.tar.gz: c2c7ceb044a6a9054da36ae775a0693458e91dac271b5d341666995dd59373b5
5
5
  SHA512:
6
- metadata.gz: d5cad909dcf688f11958ebb2012c4388d685ca9d691c4db7bc9b2fd43e3522dd6c52b4c98ac7a7f5ae9937a285069bf68608dbec27477d86ac4fad52cdbe624e
7
- data.tar.gz: 93879cc71887b23c2f8082b44ee3630844f2b5fc493b9daebff964b119a090ba8e1b28b62f844c239c27b011b852f5a978b12ba27f85aa5fc3607c4f3dea0397
6
+ metadata.gz: d7a79ba9b2a2db74515bdce0c606c99072d292813b5ef34c8963d44bcc0366fe0230bc784dcb8e489614ef1dd33ebb447d7cb215fd7f475c0fc00d51487446cf
7
+ data.tar.gz: 38e26c8853bde15845b1cd1c34bcff68f5f87db5a8e726af4451329619b54f3c4dfa26ffd83832e24ea0a743401b1e28c011316ab78b08c60cc76e42022bec58
@@ -15,6 +15,7 @@ module Fly
15
15
  attr_accessor :database_url_env_var
16
16
  attr_accessor :database_host_env_var
17
17
  attr_accessor :database_port_env_var
18
+ attr_accessor :redis_url_env_var
18
19
 
19
20
  # Cookie written and read by this middleware storing a UNIX timestamp.
20
21
  # Requests arriving before this timestamp will be replayed in the primary region.
@@ -25,33 +26,61 @@ module Fly
25
26
  attr_accessor :replay_threshold_in_seconds
26
27
 
27
28
  attr_accessor :database_url
29
+ attr_accessor :redis_url
28
30
 
29
31
  def initialize
30
32
  self.primary_region = ENV["PRIMARY_REGION"]
31
33
  self.current_region = ENV["FLY_REGION"]
32
34
  self.replay_http_methods = ["POST", "PUT", "PATCH", "DELETE"]
33
35
  self.database_url_env_var = "DATABASE_URL"
36
+ self.redis_url_env_var = "REDIS_URL"
34
37
  self.database_host_env_var = "DATABASE_HOST"
35
38
  self.database_port_env_var = "DATABASE_PORT"
36
39
  self.replay_threshold_cookie = "fly-replay-threshold"
37
40
  self.replay_threshold_in_seconds = 5
38
41
  self.database_url = ENV[database_url_env_var]
42
+ self.redis_url = ENV[redis_url_env_var]
39
43
  end
40
44
 
41
- def regional_database_uri
42
- @uri ||= URI.parse(database_url)
43
- @uri
45
+ def database_uri
46
+ @database_uri ||= URI.parse(database_url)
47
+ @database_uri
48
+ end
49
+
50
+ def regional_database_url
51
+ uri = database_uri.dup
52
+ uri.host = regional_database_host
53
+ uri.to_s
54
+ end
55
+
56
+ def regional_database_host
57
+ "#{current_region}.#{database_uri.hostname}"
44
58
  end
45
59
 
46
60
  # Rails-compatible database configuration
47
61
  def regional_database_config
48
62
  {
49
- "host" => "#{current_region}.#{regional_database_uri.hostname}",
63
+ "host" => regional_database_host,
50
64
  "port" => 5433,
51
65
  "adapter" => "postgresql"
52
66
  }
53
67
  end
54
68
 
69
+ def redis_uri
70
+ @redis_uri ||= URI.parse(redis_url)
71
+ @redis_uri
72
+ end
73
+
74
+ def regional_redis_host
75
+ "#{current_region}.#{redis_uri.hostname}"
76
+ end
77
+
78
+ def regional_redis_url
79
+ uri = redis_uri.dup
80
+ uri.host = regional_redis_host
81
+ uri.to_s
82
+ end
83
+
55
84
  def eligible_for_activation?
56
85
  database_url && primary_region && current_region && web?
57
86
  end
@@ -1,5 +1,3 @@
1
- require_relative '../fly-ruby'
2
-
3
1
  class Fly::Railtie < Rails::Railtie
4
2
  def hijack_database_connection
5
3
  ActiveSupport::Reloader.to_prepare do
@@ -30,7 +28,10 @@ class Fly::Railtie < Rails::Railtie
30
28
  app.config.middleware.insert_after ActionDispatch::Executor, Fly::RegionalDatabase::ReplayableRequestMiddleware
31
29
  # Insert the database exception handler at the bottom of the stack to take priority over other exception handlers
32
30
  app.config.middleware.use Fly::RegionalDatabase::DbExceptionHandlerMiddleware
33
- hijack_database_connection if Fly.configuration.in_secondary_region?
31
+
32
+ if Fly.configuration.in_secondary_region?
33
+ hijack_database_connection
34
+ end
34
35
  elsif Fly.configuration.web?
35
36
  puts "Warning: DATABASE_URL, PRIMARY_REGION and FLY_REGION must be set to activate the fly-ruby middleware. Middleware not loaded."
36
37
  end
@@ -1,3 +1,3 @@
1
1
  module Fly
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fly-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Sierles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-16 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack