|
@@ -0,0 +1,24 @@
|
|
|
|
|
+# frozen_string_literal: true
|
|
|
|
|
+
|
|
|
|
|
+require 'English'
|
|
|
|
|
+
|
|
|
|
|
+namespace :db do
|
|
|
|
|
+ desc 'Waits for database to be available'
|
|
|
|
|
+ task :wait_for_init do
|
|
|
|
|
+ require 'socket'
|
|
|
|
|
+
|
|
|
|
|
+ 20.times do
|
|
|
|
|
+ # postgres://postgres:postgres@db:5432/postgres
|
|
|
|
|
+ # we want: ^^ ^^^^
|
|
|
|
|
+ db_host = ENV['DATABASE_URL'].split(/:|@/)[3]
|
|
|
|
|
+ db_port = ENV['DATABASE_URL'].split(/:|@/)[4].to_i
|
|
|
|
|
+
|
|
|
|
|
+ sock = TCPSocket.new db_host, db_port
|
|
|
|
|
+ sock.close
|
|
|
|
|
+ break
|
|
|
|
|
+ rescue StandardError
|
|
|
|
|
+ $stderr.puts "db:wait_for_init: #{$ERROR_INFO}"
|
|
|
|
|
+ sleep 6
|
|
|
|
|
+ end
|
|
|
|
|
+ end
|
|
|
|
|
+end
|