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

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

                if (mentionsofme.OK)
                {
                    smallestid = long.MaxValue;
                    if (mentionsofme.Count < backfillQuota)
                    {
                        backfillQuota = mentionsofme.Count;
                    }
                    foreach (var tweet in mentionsofme)
                    {
                        _mentions.OnNext(tweet);
                        if (tweet.Id < smallestid)
                        {
                            smallestid = tweet.Id;
                        }
                        if (tweet.Id > largestid)
                        {
                            largestid = tweet.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);
        }
Esempio n. 2
0
        private async Task <long> GetMentions_Failover(long sinceid)
        {
            var largestseenid = sinceid;

            var mentionsofme = await UserSession.GetMentions(count : _sinceIdPagingSize, sinceId : sinceid);

            if (!mentionsofme.OK)
            {
                return(largestseenid);
            }
            foreach (var tweet in mentionsofme.Where(tweet => tweet.Id > sinceid))
            {
                largestseenid = tweet.Id;
                _mentions.OnNext(tweet);
            }
            return(largestseenid);
        }