Ejemplo n.º 1
0
        // these grab tweets/dms from history rather from the current stream
        //TODO: DRY these methods with <Func> goodness
        private async Task <long> GetHomeTimeLine_Backfill()
        {
            long smallestid    = 0;
            long largestid     = 0;
            int  backfillQuota = 50;
            int  backofftimer  = 30;

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

                if (hometl.OK)
                {
                    smallestid = long.MaxValue;
                    if (hometl.Count < backfillQuota)
                    {
                        backfillQuota = hometl.Count;
                    }
                    foreach (var tweet in hometl)
                    {
                        if (tweet.Id < smallestid)
                        {
                            smallestid = tweet.Id;
                        }
                        if (tweet.Id > largestid)
                        {
                            largestid = tweet.Id;
                        }
                        AddToHomeTimeLine(tweet);
                        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);
        }
Ejemplo n.º 2
0
        //TODO: DRY these methods with <Func> goodness

        private async Task <long> GetHomeTimeLine_Failover(long sinceid)
        {
            var largestseenid = sinceid;

            var hometl = await UserSession.GetHomeTimeline(count : _sinceIdPagingSize, sinceId : sinceid);

            if (!hometl.OK)
            {
                return(largestseenid);
            }
            foreach (var tweet in hometl)
            {
                AddToHomeTimeLine(tweet); // use this guard
                if (tweet.Id > sinceid)
                {
                    largestseenid = tweet.Id;
                }
            }
            return(largestseenid);
        }