Skip to content

Instantly share code, notes, and snippets.

@AzimUddin
AzimUddin / ExecuteWithRetryNode.js
Last active August 30, 2015 17:52
Azure DocumentDB node.js example of executing a method with retry to handle RequestRateTooLargeException or HTTP 429 errors
var queryIterator = documentClient.queryDocuments(collection._self, query);
executeNextWithRetry(yourCallback);
function executeNextWithRetry(callback) {
queryIterator.executeNext(function(err, results, responseHeaders) {
if(err && err.code === 429 && responseHeaders['x-ms-retry-after-ms']) {
console.log("Retrying after " + responseHeaders['x-ms-retry-after-ms']);
setTimeout(function() {
@AzimUddin
AzimUddin / MeasureRequestCharge.cs
Last active September 3, 2015 15:02
An example of measuring Request Charge for an insert Operation for Azure DocumentDB
private async Task InsertDocumentAsync(Student student, bool showDebugInfo)
{
ResourceResponse<Document> response = await client.CreateDocumentAsync(colSelfLink, student);
Console.WriteLine("{0}\tInsert Operation, # of RUs: {1}", DateTime.UtcNow, response.RequestCharge);
}
@AzimUddin
AzimUddin / QueryMasterResources.cs
Last active September 2, 2015 21:29
An example of querying Master resources in Azure DocumentDB
// Check if database exists, if not create it
Database database = client.CreateDatabaseQuery().Where(db => db.Id == id).ToArray().FirstOrDefault();
if (database == null)
{
database = await client.CreateDatabaseAsync(new Database { Id = id });
}
// Get collection
StudentsCollection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == collectionId).ToArray().FirstOrDefault();
@AzimUddin
AzimUddin / Student.cs
Created September 3, 2015 15:18
Student - a sample document
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Documents;
namespace DocumentDBPerfScaleTest
{
public class Student