lib/search.js
function getQueuedLink(callback, seconds) {
  var dateField = 'queued.lastAttempt';
  seconds = seconds || DELAY_SECONDS;
  // function to process the link
  var process = function(err, res) {
    var queuedLink = null;
    if (res && res.hits && res.hits.hits.length) {
      var hit = res.hits.hits[0]._source;
      var queued = hit.queued;
      queuedLink = { uri: hit.uri, queued: queued, total: res.hits.total };
      queued.lastAttempt = new Date().toISOString();
      queued.attempts = queued.attempts + 1;
      hit.queued = queued;

      // update accesses
      contentLib.indexContentItem(hit, {state: 'queued', member: queued.member}, function(err, res) {
        // process the link
        if (!err) {
          callback(null, queuedLink);
        } else {
          utils.passingError(err);
        }
      });
    } else {
      callback(err, null);
    }
  };

 // call query with the function
  GLOBAL.svc.indexer.formQuery({query: {
    terms: dateField + ':<now-' + seconds + 's AND state:queued AND queued.attempts:<' + MAX_ATTEMPTS
  }, sort: dateField, sourceFields : ['uri', 'title', 'queued.*'], size : 1 }, process);
}
function getQueuedLink(callback, seconds) {
  var dateField = 'queued.lastAttempt';
  seconds = seconds || DELAY_SECONDS;
  // function to process the link
  var process = function(err, res) {
    var queuedLink = null;
    if (res && res.hits && res.hits.hits.length) {
      var hit = res.hits.hits[0]._source;
      var queued = hit.queued;
      queuedLink = { uri: hit.uri, queued: queued, total: res.hits.total };
      queued.lastAttempt = new Date().toISOString();
      queued.attempts = queued.attempts + 1;
      hit.queued = queued;

      // update accesses
      contentLib.indexContentItem(hit, {state: 'queued', member: queued.member}, function(err, res) {
        // process the link
        if (!err) {
          callback(null, queuedLink);
        } else {
          utils.passingError(err);
        }
      });
    } else {
      callback(err, null);
    }
  };

 // call query with the function
  GLOBAL.svc.indexer.formQuery({query: {
    terms: dateField + ':<now-' + seconds + 's AND state:queued AND queued.attempts:<' + MAX_ATTEMPTS
  }, sort: dateField, sourceFields : ['uri', 'title', 'queued.*'], size : 1 }, process);
}
function getQueuedLink ( callback , seconds ) { var dateField = 'queued.lastAttempt' ; seconds = seconds || DELAY_SECONDS ; // function to process the link var process = function ( err , res ) { var queuedLink = null ; if ( res && res . hits && res . hits . hits . length ) { var hit = res . hits . hits [ 0 ] . _source ; var queued = hit . queued ; queuedLink = { uri : hit . uri , queued : queued , total : res . hits . total } ; queued . lastAttempt = new Date ( ) . toISOString ( ) ; queued . attempts = queued . attempts + 1 ; hit . queued = queued ; // update accesses contentLib . indexContentItem ( hit , { state : 'queued' , member : queued . member } , function ( err , res ) { // process the link if ( ! err ) { callback ( null , queuedLink ) ; } else { utils . passingError ( err ) ; } } ) ; } else { callback ( err , null ) ; } } ; // call query with the function GLOBAL . svc . indexer . formQuery ( { query : { terms : dateField + ':<now-' + seconds + 's AND state:queued AND queued.attempts:<' + MAX_ATTEMPTS } , sort : dateField , sourceFields : [ 'uri' , 'title' , 'queued.*' ] , size : 1 } , process ) ; }
Get a queued link that hasn't been attempted recently.  Callback is usually `getLinkContents`.
Get a queued link that hasn t been attempted recently . Callback is usually getLinkContents .