made twitter service more async
This commit is contained in:
parent
29d8091997
commit
e21381bee8
2 changed files with 5 additions and 14 deletions
|
@ -39,7 +39,7 @@ namespace BirdsiteLive.Pipeline.Processors
|
|||
foreach (var userWtData in syncTwitterUsers)
|
||||
{
|
||||
var user = userWtData.User;
|
||||
var tweets = RetrieveNewTweets(user);
|
||||
var tweets = await RetrieveNewTweets(user);
|
||||
_logger.LogInformation("Got " + tweets.Length + " tweets from user " + user.Acct);
|
||||
if (tweets.Length > 0 && user.LastTweetPostedId != -1)
|
||||
{
|
||||
|
@ -64,16 +64,16 @@ namespace BirdsiteLive.Pipeline.Processors
|
|||
return usersWtTweets.ToArray();
|
||||
}
|
||||
|
||||
private ExtractedTweet[] RetrieveNewTweets(SyncTwitterUser user)
|
||||
private async Task<ExtractedTweet[]> RetrieveNewTweets(SyncTwitterUser user)
|
||||
{
|
||||
var tweets = new ExtractedTweet[0];
|
||||
|
||||
try
|
||||
{
|
||||
if (user.LastTweetPostedId == -1)
|
||||
tweets = _twitterTweetsService.GetTimeline(user.Acct, 1);
|
||||
tweets = await _twitterTweetsService.GetTimelineAsync(user.Acct, 1);
|
||||
else
|
||||
tweets = _twitterTweetsService.GetTimeline(user.Acct, 200, user.LastTweetSynchronizedForAllFollowersId);
|
||||
tweets = await _twitterTweetsService.GetTimelineAsync(user.Acct, 200, user.LastTweetSynchronizedForAllFollowersId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -18,8 +18,7 @@ namespace BirdsiteLive.Twitter
|
|||
public interface ITwitterTweetsService
|
||||
{
|
||||
Task<ExtractedTweet> GetTweetAsync(long statusId);
|
||||
ExtractedTweet GetTweet(long statusId);
|
||||
ExtractedTweet[] GetTimeline(string username, int nberTweets, long fromTweetId = -1);
|
||||
Task<ExtractedTweet[]> GetTimelineAsync(string username, int nberTweets, long fromTweetId = -1);
|
||||
}
|
||||
|
||||
public class TwitterTweetsService : ITwitterTweetsService
|
||||
|
@ -41,10 +40,6 @@ namespace BirdsiteLive.Twitter
|
|||
#endregion
|
||||
|
||||
|
||||
public ExtractedTweet GetTweet(long statusId)
|
||||
{
|
||||
return GetTweetAsync(statusId).Result;
|
||||
}
|
||||
public async Task<ExtractedTweet> GetTweetAsync(long statusId)
|
||||
{
|
||||
|
||||
|
@ -79,10 +74,6 @@ namespace BirdsiteLive.Twitter
|
|||
}
|
||||
}
|
||||
|
||||
public ExtractedTweet[] GetTimeline(string username, int nberTweets, long fromTweetId = -1)
|
||||
{
|
||||
return GetTimelineAsync(username, nberTweets, fromTweetId).Result;
|
||||
}
|
||||
public async Task<ExtractedTweet[]> GetTimelineAsync(string username, int nberTweets, long fromTweetId = -1)
|
||||
{
|
||||
if (nberTweets < 5)
|
||||
|
|
Reference in a new issue