wait_pg 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/wait_pg +30 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16907dc9186b682642d7176bd967d38204009462a821a58407b0d11dc59ed086
4
- data.tar.gz: 15e7f0cce220e116102367f1abde99bbedc51346401a80175ac982385ac6ccac
3
+ metadata.gz: 2aeba2bbc35ea77471696967ab1c05e4ba4b9dc89b1b85386f04d480367dd832
4
+ data.tar.gz: 5ef2c0f9253b2bd8676ec4b9e2399d82484aa4814500c8775fc68fe3ef6dc55e
5
5
  SHA512:
6
- metadata.gz: f035bc4f8397514fcf7a8d21b3eca5947e7d82b3327960c01f516e449a5a4b87ec5383a669f986d7ad5a53d4e607e0be69cd868903fa51e36fb63659a5d956cb
7
- data.tar.gz: c0c30b482b0cfcf4bbf644684efdc1ff9b9ccdabfd6d81aa6bdc28124b1c51e5b1f5d82c0cfbf45713efda0b29c464e62d54fd29bf96d293e7ccae8b0c84a8b6
6
+ metadata.gz: 800c913c3d6e98f37dec2a22b0cfe987556a402c65973b9ee987afdee5616f32578554266f5b9722d6e269278a567eaf0e97a4464606da4a4377b17f783f80bf
7
+ data.tar.gz: 870a969051ef69439db4057af03d63af49e5f09270734cfaf1019fbb9f891b6b817871c1e230d293ee7357ae6a9a51ef9e3e2ac4f53ea92a1a7a844fca4445b9
data/bin/wait_pg CHANGED
@@ -3,30 +3,44 @@ require 'erb'
3
3
  require 'pg'
4
4
  require 'yaml'
5
5
 
6
- # Wait for 60 seconds for a connection
7
- retries = 30
8
- interval = 2
6
+ SUCCESS = 0
7
+ ERROR = 1
8
+
9
+ def connection_options
10
+ rails_env = ENV.fetch('RAILS_ENV') { 'development' }
11
+
12
+ path = File.expand_path('./config/database.yml')
13
+ yaml = YAML.load(ERB.new(File.read(path)).result)[rails_env]
14
+
15
+ # Active Record uses it as a default
16
+ return ENV['DATABASE_URL'] unless yaml&.exist?
9
17
 
10
- rails_env = ENV.fetch('RAILS_ENV') { 'development' }
11
- database_yml = YAML.load(ERB.new(File.read(File.expand_path('./config/database.yml'))).result)[rails_env]
18
+ # Set the default adapter (for cases like PostGIS)
19
+ config = yaml['url'].sub(/^.*:\/\//, 'postgres://')
12
20
 
13
- connection_options = {
14
- user: database_yml['username'],
15
- host: database_yml['host'],
16
- password: database_yml['password'],
17
- port: database_yml['port'],
18
- }
21
+ config ||= {
22
+ user: yaml['username'],
23
+ host: yaml['host'],
24
+ password: yaml['password'],
25
+ port: yaml['port'],
26
+ }
19
27
 
20
- if database_yml['database_url'] && !database_yml['database_url'].empty?
21
- # Use the default adapter
22
- connection_options = database_yml['database_url'].gsub(/^.*:\/\//, 'postgres://')
28
+ config ||= ENV['DATABASE_URL']
23
29
  end
24
30
 
31
+ def connection_successful?
32
+ PG::PQPING_OK == PG::Connection.ping(connection_options)
33
+ end
34
+
35
+ # Wait for 60 seconds for a connection
36
+ retries = 30
37
+ interval = 2
38
+
25
39
  puts 'Waiting for PostgreSQL...'
26
40
 
27
41
  retries.times do
28
- exit 0 if PG::PQPING_OK == PG::Connection.ping(connection_options)
42
+ exit SUCCESS if connection_successful?
29
43
  sleep interval
30
44
  end
31
45
 
32
- exit 1
46
+ exit ERROR
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wait_pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - mroutis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-01 00:00:00.000000000 Z
11
+ date: 2018-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg