Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
try to survive MongoDB connection failure
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Aug 9, 2011
1 parent 2113ebd commit ef24917
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ef24917

Please sign in to comment.