Skip to content

Instantly share code, notes, and snippets.

@vovayartsev
Last active August 29, 2015 14:16
Show Gist options
  • Save vovayartsev/1d9bbe959c6b20d71d73 to your computer and use it in GitHub Desktop.
Save vovayartsev/1d9bbe959c6b20d71d73 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def system(arg)
puts "--> #{arg}"
end
# no need to wait for backup to finish
# see http://dba.stackexchange.com/questions/13742/does-running-pg-dump-on-live-db-produce-consistent-backups
# the only question: does backup block DDL operations?
def launch_pg_backup
puts "Initiating PG Backup in a thread"
puts "And returning as soon as we start seeing it's logs"
end
system "git push heroku HEAD:master --force"
migration_status = `heroku run bin/probe_migrations.rb`
case migration_status
when /NEED MIGRATIONS/
launch_pg_backup
system 'heroku run rake db:migrate'
when /UP TO DATE/
puts 'OK Migrations not needed'
else
puts '!!! Deploy failed'
system 'heroku releases:rollback'
end
#!/usr/bin/env ruby
require 'rubygems'
require 'active_record'
require 'yaml'
dbconfig = YAML::load(File.open('config/database.yml'))
ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"] || dbconfig[ENV['RAILS_ENV'] || 'development'])
puts(ActiveRecord::Migrator.needs_migration? ? "NEED MIGRATIONS" : "UP TO DATE")
web: bin/watchdog.rb && bundle exec rails server thin -p $PORT
resque: bin/watchdog.rb && bundle exec resque
#!/usr/bin/env ruby
require 'rubygems'
require 'active_record'
require 'yaml'
dbconfig = YAML::load(File.open('config/database.yml'))
ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"] || dbconfig[ENV['RAILS_ENV'] || 'development'])
if ActiveRecord::Migrator.needs_migration?
Thread.new do
while ActiveRecord::Migrator.needs_migration?
puts '--> Migrations still pending...'
sleep 3
end
exit 0
end
if ENV['PORT']
require 'sinatra'
get '*' do
"I'm under maintenance right now. BRB"
end
else
sleep 3600
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment