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.
- checksums.yaml +4 -4
- data/bin/wait_pg +30 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2aeba2bbc35ea77471696967ab1c05e4ba4b9dc89b1b85386f04d480367dd832
|
4
|
+
data.tar.gz: 5ef2c0f9253b2bd8676ec4b9e2399d82484aa4814500c8775fc68fe3ef6dc55e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
11
|
-
|
18
|
+
# Set the default adapter (for cases like PostGIS)
|
19
|
+
config = yaml['url'].sub(/^.*:\/\//, 'postgres://')
|
12
20
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
21
|
+
config ||= {
|
22
|
+
user: yaml['username'],
|
23
|
+
host: yaml['host'],
|
24
|
+
password: yaml['password'],
|
25
|
+
port: yaml['port'],
|
26
|
+
}
|
19
27
|
|
20
|
-
|
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
|
42
|
+
exit SUCCESS if connection_successful?
|
29
43
|
sleep interval
|
30
44
|
end
|
31
45
|
|
32
|
-
exit
|
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.
|
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-
|
11
|
+
date: 2018-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|