Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cyril David
committed
Mar 20, 2010
1 parent
6c801d1
commit bcf6326
Showing
10 changed files
with
146 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ | |
/config/database.yml | ||
/uploads | ||
/config/deployed_at | ||
/dump.rdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module ActiveRecord::ConnectionAdapters | ||
class MysqlAdapter | ||
alias_method :execute_without_retry, :execute | ||
|
||
def execute(*args) | ||
execute_without_retry(*args) | ||
rescue ActiveRecord::StatementInvalid => e | ||
if e.message =~ /server has gone away/i | ||
warn "Server timed out, retrying" | ||
reconnect! | ||
retry | ||
else | ||
raise e | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
rack_env = ENV['RACK_ENV'] || "production" | ||
root_dir = ENV['ROOT_DIR'] || "/u/apps/boughtstuff/current" | ||
num_workers = rack_env == 'production' ? 1 : 2 | ||
|
||
num_workers.times do |num| | ||
God.watch do |w| | ||
w.name = "resque-#{num}" | ||
w.group = 'resque' | ||
w.interval = 30.seconds | ||
w.env = {"QUEUE"=>"twitter", "RACK_ENV"=>rack_env} | ||
w.start = "/opt/mri-1.9.1-boughtstuff/bin/rake -f #{root_dir}/Rakefile resque:work" | ||
|
||
w.uid = 'ubuntu' | ||
w.gid = 'ubuntu' | ||
|
||
# retart if memory gets too high | ||
w.transition(:up, :restart) do |on| | ||
on.condition(:memory_usage) do |c| | ||
c.above = 350.megabytes | ||
c.times = 2 | ||
end | ||
end | ||
|
||
# determine the state on startup | ||
w.transition(:init, { true => :up, false => :start }) do |on| | ||
on.condition(:process_running) do |c| | ||
c.running = true | ||
end | ||
end | ||
|
||
# determine when process has finished starting | ||
w.transition([:start, :restart], :up) do |on| | ||
on.condition(:process_running) do |c| | ||
c.running = true | ||
c.interval = 5.seconds | ||
end | ||
|
||
# failsafe | ||
on.condition(:tries) do |c| | ||
c.times = 5 | ||
c.transition = :start | ||
c.interval = 5.seconds | ||
end | ||
end | ||
|
||
# start if process is not running | ||
w.transition(:up, :start) do |on| | ||
on.condition(:process_running) do |c| | ||
c.running = false | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
namespace :heroku do | ||
desc "Generate a .gems manifest file for use with heroku" | ||
task :create_gems_manifest do | ||
skip = %w(factory_girl database_cleaner daemons eventmachine faker | ||
fakeweb fastthread gemcutter json_pure linecache19 | ||
mysql sqlite3-ruby nokogiri rspec-core rspec rspec-expectations | ||
rspec-mocks rspec-rails-matchers ruby-debug-base19 ruby-debug19 | ||
thin timecop webrat ZenTest treetop cucumber term-ansicolor | ||
polyglot image_science RubyInline heroku configuration | ||
launchy) | ||
|
||
deps = %w(tzinfo builder memcache-client rack rack-test rack-mount | ||
erubis mail text-format thor bundler i18n) | ||
|
||
puts "\n-----> Starting extraction of config/rvm.gems" | ||
|
||
rvm_gems = File.read("config/rvm.gems").split("\n") | ||
|
||
puts " Read #{rvm_gems.size - 1} gem entries..." | ||
|
||
print "-----> Sorting through the different gems... " | ||
gems = [] | ||
rvm_gems.each do |gem| | ||
name, version = gem.split(" -v") | ||
|
||
next if gem.index('#') == 0 | ||
next if skip.include?(name) | ||
|
||
if deps.include?(name) | ||
gems.unshift([name, version]) | ||
else | ||
gems << [ name, version ] | ||
end | ||
end | ||
puts "Done!" | ||
print "-----> Writing the .gems file now... " | ||
|
||
File.open('.gems', 'w') do |f| | ||
gems.each do |name, version| | ||
f.write "#{name} --version #{version}\n" | ||
end | ||
f.write "pg" | ||
end | ||
|
||
puts "Done!" | ||
puts " Wrote #{gems.size + 1} gems to the manifest!" | ||
end | ||
|
||
desc "Deploy to heroku" | ||
task :deploy => [ :create_heroku_gems_manifest, "asset:packager:build_all" ] do | ||
`git add . && git commit -m "updated .gems manifest on #{Time.now.utc}" && git push heroku-staging master` | ||
|
||
`heroku rake asset:upload:s3` | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'resque/tasks' | ||
|
||
namespace :resque do | ||
task :setup => :environment | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters