Skip to content

Instantly share code, notes, and snippets.

@kowsik
Created January 21, 2011 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kowsik/789354 to your computer and use it in GitHub Desktop.
Save kowsik/789354 to your computer and use it in GitHub Desktop.
optimistic update_doc
def update_doc doc
loop do
yield doc
begin
save_doc doc
break
rescue RestClient::RequestFailed => e
if e.http_code == 409
doc = get doc['_id']
next
else
raise e
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment