Permalink
Browse files

try to survive MongoDB connection failure

  • Loading branch information...
1 parent 2113ebd commit ef249178de16df56bbe5cd3c8015fc342dca2ff0 @mislav committed Aug 9, 2011
Showing with 8 additions and 2 deletions.
  1. +6 −2 app.rb
  2. +2 −0 models.rb
View
8 app.rb
@@ -48,8 +48,12 @@
end
configure :development, :production do
- Mingo.connect settings.mongodb.url
- User.collection.create_index(:username, :unique => true)
+ begin
+ Mingo.connect settings.mongodb.url
+ User.collection.create_index(:username, :unique => true)
+ rescue Mongo::ConnectionFailure
+ warn "MongoDB connection failed: #{$!}"
+ end
ActiveSupport::Cache::Store.instrument = true
View
@@ -30,6 +30,8 @@ def self.[](id)
user.save
end
end
+ rescue NoMethodError
+ new(user_id: id.to_i)
end
def self.from_token(token)

0 comments on commit ef24917

Please sign in to comment.