async Task RevokeRetry(UserStreamer Streamer)
        {
            if (RevokeRetryUserID.ContainsKey(Streamer.Token.UserId))
            {
                await db.DeleteToken(Streamer.Token.UserId).ConfigureAwait(false);

                RevokeRetryUserID.TryRemove(Streamer.Token.UserId, out byte z);
                RemoveStreamer(Streamer);
            }
            else
            {
                RevokeRetryUserID.TryAdd(Streamer.Token.UserId, 0);
            }                                                               //次回もRevokeされてたら消えてもらう
        }
 bool Add(Tokens t)
 {
     if (t == null)
     {
         return(false);
     }
     if (Streamers.ContainsKey(t.UserId))
     {
         //Console.WriteLine("{0} {1}: Already running.", DateTime.Now, t.UserId);
         return(false);
     }
     else
     {
         //Console.WriteLine("{0} {1}: Assigned.", DateTime.Now, t.UserId);
         UserStreamer s = new UserStreamer(t);
         return(Streamers.TryAdd(t.UserId, s));
     }
 }
Esempio n. 3
0
        public async ValueTask <int> Proceed()
        {
            Tokens[] tokens = await db.Selecttoken(DBHandler.SelectTokenMode.All);

            if (tokens.Length > 0)
            {
                Console.WriteLine("App: {0} Accounts to REST", tokens.Length);
            }
            ActionBlock <Tokens> RestProcess = new ActionBlock <Tokens>(async(t) =>
            {
                UserStreamer s = new UserStreamer(t);
                await s.RestFriend();
                await s.RestBlock();
                await s.RestMyTweet();
            }, new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = config.crawl.RestTweetThreads,
                BoundedCapacity        = config.crawl.RestTweetThreads << 1
            });
            Stopwatch sw = Stopwatch.StartNew();

            foreach (Tokens t in tokens)
            {
                await RestProcess.SendAsync(t);

                if (sw.ElapsedMilliseconds > 60000)
                {
                    Counter.PrintReset();
                    GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; //これは毎回必要らしい
                    GC.Collect();
                    sw.Restart();
                }
            }
            RestProcess.Complete();
            await RestProcess.Completion;

            return(tokens.Length);
        }
 ///<summary>Revokeされた後の処理</summary>
 void RemoveStreamer(UserStreamer Streamer)
 {
     Streamer.Dispose();
     Streamers.TryRemove(Streamer.Token.UserId, out UserStreamer z);  //つまり死んだStreamerは除外される
     Console.WriteLine("{0}: Streamer removed", Streamer.Token.UserId);
 }