private async Task <long> GetDirectMessages_Sent_Backfill() { long smallestid = 0; long largestid = 0; int backfillQuota = 50; int backofftimer = 30; do { var mysentdms = await UserSession.GetDirectMessagesSent(count : _pagingSize, maxId : smallestid); if (mysentdms.OK) { smallestid = long.MaxValue; if (mysentdms.Count < backfillQuota) { backfillQuota = mysentdms.Count; } foreach (var dm in mysentdms) { _directmessages.OnNext(dm); if (dm.Id < smallestid) { smallestid = dm.Id; } if (dm.Id > largestid) { largestid = dm.Id; } backfillQuota--; } await Task.Delay(_multiFetchBackoffTimer); } 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) { break; } backofftimer = backofftimer * 2; } } while (backfillQuota > 0); return(largestid); }
private async Task <long> GetDirectMessages_Sent_Failover(long sinceid) { var largestseenid = sinceid; var mysentdms = await UserSession.GetDirectMessagesSent(count : _pagingSize, sinceId : sinceid); if (!mysentdms.OK) { return(largestseenid); } foreach (var dm in mysentdms.Where(dm => dm.Id > sinceid)) { largestseenid = dm.Id; _directmessages.OnNext(dm); } return(largestseenid); }