examples/samples/retrypolicysample.js
function setCustomRetryPolicy() {
  console.log('Starting Sample 2 - setCustomRetryPolicy.');

  // Step 1 : Set the retry policy to customized retry policy which will
  // not retry on any failing status code other than the excepted one.
  var retryOnContainerBeingDeleted = new RetryPolicyFilter();
  retryOnContainerBeingDeleted.retryCount = 5;
  retryOnContainerBeingDeleted.retryInterval = 5000;

  retryOnContainerBeingDeleted.shouldRetry = function (statusCode, retryData) {
    console.log(' Made the request at ' + new Date().toUTCString() + ', received StatusCode: ' + statusCode);

    var retryInfo = {};

    // retries on any bad status code other than 409 
    if (statusCode >= 300 && statusCode !== 409 && statusCode !== 500) {
      retryInfo.retryable = false;
    } else {
      var currentCount = (retryData && retryData.retryCount) ? retryData.retryCount : 0;

      retryInfo = {
        retryInterval: this.retryInterval + 2000 * currentCount,
        retryable: currentCount < this.retryCount
      };
    }

    return retryInfo;
  };

  blobService = azure.createBlobService().withFilter(retryOnContainerBeingDeleted);

  // optionally set a proxy
  /*var proxy = {
    protocol: 'http:',
    host: '127.0.0.1',
    port: 8888
  };

  blobService.setProxy(proxy);*/


  // Step 2: Create the container
  createContainer(function () {

    // Step 3: Fetch attributes from the container using LocationMode.SECONDARY_THEN_PRIMARY
    fetchAttributesContainer(function () {

      // Step 4: Lease the container
      leaseContainer(function () {

        // Step 5: Lease the container again, retrying until it succeeds
        leaseContainer(function () {

          // Step 6: Delete the container
          deleteContainer(function () {
            console.log('Ending Sample 2 - setCustomRetryPolicy.');
          });
        });
      });
    });
  });
}
function setCustomRetryPolicy() {
  console.log('Starting Sample 2 - setCustomRetryPolicy.');

  // Step 1 : Set the retry policy to customized retry policy which will
  // not retry on any failing status code other than the excepted one.
  var retryOnContainerBeingDeleted = new RetryPolicyFilter();
  retryOnContainerBeingDeleted.retryCount = 5;
  retryOnContainerBeingDeleted.retryInterval = 5000;

  retryOnContainerBeingDeleted.shouldRetry = function (statusCode, retryData) {
    console.log(' Made the request at ' + new Date().toUTCString() + ', received StatusCode: ' + statusCode);

    var retryInfo = {};

    // retries on any bad status code other than 409 
    if (statusCode >= 300 && statusCode !== 409 && statusCode !== 500) {
      retryInfo.retryable = false;
    } else {
      var currentCount = (retryData && retryData.retryCount) ? retryData.retryCount : 0;

      retryInfo = {
        retryInterval: this.retryInterval + 2000 * currentCount,
        retryable: currentCount < this.retryCount
      };
    }

    return retryInfo;
  };

  blobService = azure.createBlobService().withFilter(retryOnContainerBeingDeleted);

  // optionally set a proxy
  /*var proxy = {
    protocol: 'http:',
    host: '127.0.0.1',
    port: 8888
  };

  blobService.setProxy(proxy);*/


  // Step 2: Create the container
  createContainer(function () {

    // Step 3: Fetch attributes from the container using LocationMode.SECONDARY_THEN_PRIMARY
    fetchAttributesContainer(function () {

      // Step 4: Lease the container
      leaseContainer(function () {

        // Step 5: Lease the container again, retrying until it succeeds
        leaseContainer(function () {

          // Step 6: Delete the container
          deleteContainer(function () {
            console.log('Ending Sample 2 - setCustomRetryPolicy.');
          });
        });
      });
    });
  });
}
function setCustomRetryPolicy ( ) { console . log ( 'Starting Sample 2 - setCustomRetryPolicy.' ) ; // Step 1 : Set the retry policy to customized retry policy which will // not retry on any failing status code other than the excepted one. var retryOnContainerBeingDeleted = new RetryPolicyFilter ( ) ; retryOnContainerBeingDeleted . retryCount = 5 ; retryOnContainerBeingDeleted . retryInterval = 5000 ; retryOnContainerBeingDeleted . shouldRetry = function ( statusCode , retryData ) { console . log ( ' Made the request at ' + new Date ( ) . toUTCString ( ) + ', received StatusCode: ' + statusCode ) ; var retryInfo = { } ; // retries on any bad status code other than 409  if ( statusCode >= 300 && statusCode !== 409 && statusCode !== 500 ) { retryInfo . retryable = false ; } else { var currentCount = ( retryData && retryData . retryCount ) ? retryData . retryCount : 0 ; retryInfo = { retryInterval : this . retryInterval + 2000 * currentCount , retryable : currentCount < this . retryCount } ; } return retryInfo ; } ; blobService = azure . createBlobService ( ) . withFilter ( retryOnContainerBeingDeleted ) ; // optionally set a proxy /*var proxy = {
    protocol: 'http:',
    host: '127.0.0.1',
    port: 8888
  };

  blobService.setProxy(proxy);*/ // Step 2: Create the container createContainer ( function ( ) { // Step 3: Fetch attributes from the container using LocationMode.SECONDARY_THEN_PRIMARY fetchAttributesContainer ( function ( ) { // Step 4: Lease the container leaseContainer ( function ( ) { // Step 5: Lease the container again, retrying until it succeeds leaseContainer ( function ( ) { // Step 6: Delete the container deleteContainer ( function ( ) { console . log ( 'Ending Sample 2 - setCustomRetryPolicy.' ) ; } ) ; } ) ; } ) ; } ) ; } ) ; }
Demonstrate how to use custom retry policy.
Any custom retry logic may be used by simply creating and setting RetryPolicyFilter instance.
Demonstrate how to use custom retry policy . Any custom retry logic may be used by simply creating and setting RetryPolicyFilter instance .