Exemplo n.º 1
0
        private async Task <long> GetDirectMessages_Received_Backfill()
        {
            long smallestid    = 0;
            long largestid     = 0;
            int  backfillQuota = 50;
            int  backofftimer  = 30;

            do
            {
                var dmrecd = await UserSession.GetDirectMessages(count : _pagingSize, maxId : smallestid);

                if (dmrecd.OK)
                {
                    smallestid = long.MaxValue;
                    // if the Count of items returned is less than the backfill quota, we have run out of messages.
                    // this will decrement the backfill quota to zero, falling out of the loop
                    if (dmrecd.Count < backfillQuota)
                    {
                        backfillQuota = dmrecd.Count;
                    }
                    foreach (var dm in dmrecd)
                    {
                        _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);
        }
Exemplo n.º 2
0
        private async Task <long> GetDirectMessages_Received_Failover(long sinceid)
        {
            var largestseenid = sinceid;

            var dmrecd = await UserSession.GetDirectMessages(count : _pagingSize, sinceId : sinceid);

            if (!dmrecd.OK)
            {
                return(largestseenid);
            }
            foreach (var dm in dmrecd.Where(dm => dm.Id > sinceid))
            {
                largestseenid = dm.Id;
                _directmessages.OnNext(dm);
            }
            return(largestseenid);
        }