#!/usr/local/bin/ruby
#Simple script to delay until dockerized postgis is ready.
#Success is when a connection to riskscape-postgis:5432 succeeds.
require 'socket'
require 'time'

target = 'riskscape-postgis'
sleep_time = 2
while (true)
  begin
    s = Socket.new Socket::AF_INET, Socket::SOCK_STREAM
    s.connect Socket.pack_sockaddr_in(5432, target)
    break;
  rescue
    #We don't want to stop waiting
  end
  sleep(sleep_time)
end
