Class: Fly::Configuration
- Inherits:
-
Object
- Object
- Fly::Configuration
- Defined in:
- lib/fly-ruby/configuration.rb
Instance Attribute Summary collapse
-
#current_region ⇒ Object
Set the region where this instance of the application is deployed.
-
#database_host_env_var ⇒ Object
Returns the value of attribute database_host_env_var.
-
#database_port_env_var ⇒ Object
Returns the value of attribute database_port_env_var.
-
#database_url ⇒ Object
Returns the value of attribute database_url.
-
#database_url_env_var ⇒ Object
Environment variables related to the database connection.
-
#primary_region ⇒ Object
Set the region where the primary database lives, i.e “ams”.
-
#redis_url ⇒ Object
Returns the value of attribute redis_url.
-
#redis_url_env_var ⇒ Object
Returns the value of attribute redis_url_env_var.
-
#replay_http_methods ⇒ Object
Automatically replay these HTTP methods in the primary region.
-
#replay_threshold_cookie ⇒ Object
Cookie written and read by this middleware storing a UNIX timestamp.
-
#replay_threshold_in_seconds ⇒ Object
How long, in seconds, should all requests from the same client be replayed in the primary region after a successful write replay.
Instance Method Summary collapse
-
#console? ⇒ Boolean
Is the current process a Rails console?.
- #database_uri ⇒ Object
- #eligible_for_activation? ⇒ Boolean
- #in_secondary_region? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#rake_task? ⇒ Boolean
Is the current process a rake task?.
- #redis_uri ⇒ Object
-
#regional_database_config ⇒ Object
Rails-compatible database configuration.
- #regional_database_host ⇒ Object
- #regional_database_url ⇒ Object
- #regional_redis_host ⇒ Object
- #regional_redis_url ⇒ Object
- #web? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fly-ruby/configuration.rb', line 31 def initialize self.primary_region = ENV["PRIMARY_REGION"] self.current_region = ENV["FLY_REGION"] self.replay_http_methods = ["POST", "PUT", "PATCH", "DELETE"] self.database_url_env_var = "DATABASE_URL" self.redis_url_env_var = "REDIS_URL" self.database_host_env_var = "DATABASE_HOST" self.database_port_env_var = "DATABASE_PORT" self. = "fly-replay-threshold" self.replay_threshold_in_seconds = 5 self.database_url = ENV[database_url_env_var] self.redis_url = ENV[redis_url_env_var] end |
Instance Attribute Details
#current_region ⇒ Object
Set the region where this instance of the application is deployed
4 5 6 |
# File 'lib/fly-ruby/configuration.rb', line 4 def current_region @current_region end |
#database_host_env_var ⇒ Object
Returns the value of attribute database_host_env_var.
16 17 18 |
# File 'lib/fly-ruby/configuration.rb', line 16 def database_host_env_var @database_host_env_var end |
#database_port_env_var ⇒ Object
Returns the value of attribute database_port_env_var.
17 18 19 |
# File 'lib/fly-ruby/configuration.rb', line 17 def database_port_env_var @database_port_env_var end |
#database_url ⇒ Object
Returns the value of attribute database_url.
28 29 30 |
# File 'lib/fly-ruby/configuration.rb', line 28 def database_url @database_url end |
#database_url_env_var ⇒ Object
Environment variables related to the database connection. These get by this middleware in secondary regions, so they must be interpolated rather than defined directly in the configuration.
15 16 17 |
# File 'lib/fly-ruby/configuration.rb', line 15 def database_url_env_var @database_url_env_var end |
#primary_region ⇒ Object
Set the region where the primary database lives, i.e “ams”
7 8 9 |
# File 'lib/fly-ruby/configuration.rb', line 7 def primary_region @primary_region end |
#redis_url ⇒ Object
Returns the value of attribute redis_url.
29 30 31 |
# File 'lib/fly-ruby/configuration.rb', line 29 def redis_url @redis_url end |
#redis_url_env_var ⇒ Object
Returns the value of attribute redis_url_env_var.
18 19 20 |
# File 'lib/fly-ruby/configuration.rb', line 18 def redis_url_env_var @redis_url_env_var end |
#replay_http_methods ⇒ Object
Automatically replay these HTTP methods in the primary region
10 11 12 |
# File 'lib/fly-ruby/configuration.rb', line 10 def replay_http_methods @replay_http_methods end |
#replay_threshold_cookie ⇒ Object
Cookie written and read by this middleware storing a UNIX timestamp. Requests arriving before this timestamp will be replayed in the primary region.
22 23 24 |
# File 'lib/fly-ruby/configuration.rb', line 22 def @replay_threshold_cookie end |
#replay_threshold_in_seconds ⇒ Object
How long, in seconds, should all requests from the same client be replayed in the primary region after a successful write replay
26 27 28 |
# File 'lib/fly-ruby/configuration.rb', line 26 def replay_threshold_in_seconds @replay_threshold_in_seconds end |
Instance Method Details
#console? ⇒ Boolean
Is the current process a Rails console?
93 94 95 |
# File 'lib/fly-ruby/configuration.rb', line 93 def console? defined?(::Rails::Console) && $stdout.isatty && $stdin.isatty end |
#database_uri ⇒ Object
45 46 47 48 |
# File 'lib/fly-ruby/configuration.rb', line 45 def database_uri @database_uri ||= URI.parse(database_url) @database_uri end |
#eligible_for_activation? ⇒ Boolean
84 85 86 |
# File 'lib/fly-ruby/configuration.rb', line 84 def eligible_for_activation? database_url && primary_region && current_region && web? end |
#in_secondary_region? ⇒ Boolean
88 89 90 |
# File 'lib/fly-ruby/configuration.rb', line 88 def in_secondary_region? primary_region && primary_region != current_region end |
#rake_task? ⇒ Boolean
Is the current process a rake task?
98 99 100 |
# File 'lib/fly-ruby/configuration.rb', line 98 def rake_task? defined?(::Rake) && !Rake.application.top_level_tasks.empty? end |
#redis_uri ⇒ Object
69 70 71 72 |
# File 'lib/fly-ruby/configuration.rb', line 69 def redis_uri @redis_uri ||= URI.parse(redis_url) @redis_uri end |
#regional_database_config ⇒ Object
Rails-compatible database configuration
61 62 63 64 65 66 67 |
# File 'lib/fly-ruby/configuration.rb', line 61 def regional_database_config { "host" => regional_database_host, "port" => 5433, "adapter" => "postgresql" } end |
#regional_database_host ⇒ Object
56 57 58 |
# File 'lib/fly-ruby/configuration.rb', line 56 def regional_database_host "#{current_region}.#{database_uri.hostname}" end |
#regional_database_url ⇒ Object
50 51 52 53 54 |
# File 'lib/fly-ruby/configuration.rb', line 50 def regional_database_url uri = database_uri.dup uri.host = regional_database_host uri.to_s end |
#regional_redis_host ⇒ Object
74 75 76 |
# File 'lib/fly-ruby/configuration.rb', line 74 def regional_redis_host "#{current_region}.#{redis_uri.hostname}" end |
#regional_redis_url ⇒ Object
78 79 80 81 82 |
# File 'lib/fly-ruby/configuration.rb', line 78 def regional_redis_url uri = redis_uri.dup uri.host = regional_redis_host uri.to_s end |
#web? ⇒ Boolean
102 103 104 |
# File 'lib/fly-ruby/configuration.rb', line 102 def web? !console? && !rake_task? end |