private async Task <long> GetSearchTimeLine_Backfill() { int backofftimer = 30; long smallestid = 0; long largestid = 0; int backfillQuota = 50; do { //TODO: need to unhardcode SearchResultType just for backfills var searchtl = await TwitterSession.SearchFor(searchText : _currentSearchText, searchResponseType : SearchResultType.Recent, count : _pagingSize, maxId : smallestid); if (searchtl.OK) { smallestid = long.MaxValue; if (searchtl.Tweets.Count() < backfillQuota) { backfillQuota = searchtl.Tweets.Count(); } foreach (var tweet in searchtl.Tweets) { if (tweet.Id < smallestid) { smallestid = tweet.Id; } if (tweet.Id > largestid) { largestid = tweet.Id; } _searchtimeline.OnNext(tweet); backfillQuota--; } } else { // The Backoff will trigger 7 times before just giving up // once at 30s, 60s, 1m, 2m, 4m, 8m and then 16m // note that the last call into this will be 1m above the 15 "rate limit reset" window await Task.Delay(TimeSpan.FromSeconds(backofftimer)); if (backofftimer > _maxbackoff) { backofftimer = backofftimer * 2; } } } while (backfillQuota > 0); return(largestid); }
private async Task <long> GetSearchTimeLine_Failover(long sinceid) { var largestseenid = sinceid; var searchtl = await TwitterSession.SearchFor(searchText : _currentSearchText, searchResponseType : SearchResultType.Recent, count : _pagingSize, sinceId : sinceid); if (!searchtl.OK) { return(largestseenid); } foreach (var tweet in searchtl.Tweets.Where(tweet => tweet.Id > sinceid)) { if (tweet.Id > sinceid) { largestseenid = tweet.Id; } _searchtimeline.OnNext(tweet); } return(largestseenid); }