Merge pull request #92 from NicolasConstant/develop

0.14.5 PR
This commit is contained in:
Nicolas Constant 2021-02-16 01:54:07 +01:00 committed by GitHub
commit 4fbb691672
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 13 deletions

View file

@ -5,27 +5,57 @@ using System.Threading.Tasks;
using BirdsiteLive.DAL.Contracts; using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.Pipeline.Contracts; using BirdsiteLive.Pipeline.Contracts;
using BirdsiteLive.Pipeline.Models; using BirdsiteLive.Pipeline.Models;
using Microsoft.Extensions.Logging;
namespace BirdsiteLive.Pipeline.Processors namespace BirdsiteLive.Pipeline.Processors
{ {
public class SaveProgressionProcessor : ISaveProgressionProcessor public class SaveProgressionProcessor : ISaveProgressionProcessor
{ {
private readonly ITwitterUserDal _twitterUserDal; private readonly ITwitterUserDal _twitterUserDal;
private readonly ILogger<SaveProgressionProcessor> _logger;
#region Ctor #region Ctor
public SaveProgressionProcessor(ITwitterUserDal twitterUserDal) public SaveProgressionProcessor(ITwitterUserDal twitterUserDal, ILogger<SaveProgressionProcessor> logger)
{ {
_twitterUserDal = twitterUserDal; _twitterUserDal = twitterUserDal;
_logger = logger;
} }
#endregion #endregion
public async Task ProcessAsync(UserWithTweetsToSync userWithTweetsToSync, CancellationToken ct) public async Task ProcessAsync(UserWithTweetsToSync userWithTweetsToSync, CancellationToken ct)
{ {
var userId = userWithTweetsToSync.User.Id; try
var lastPostedTweet = userWithTweetsToSync.Tweets.Select(x => x.Id).Max(); {
var minimumSync = userWithTweetsToSync.Followers.Select(x => x.FollowingsSyncStatus[userId]).Min(); if (userWithTweetsToSync.Tweets.Length == 0)
var now = DateTime.UtcNow; {
await _twitterUserDal.UpdateTwitterUserAsync(userId, lastPostedTweet, minimumSync, now); _logger.LogWarning("No tweets synchronized");
return;
}
if(userWithTweetsToSync.Followers.Length == 0)
{
_logger.LogWarning("No Followers found for {User}", userWithTweetsToSync.User.Acct);
return;
}
var userId = userWithTweetsToSync.User.Id;
var followingSyncStatuses = userWithTweetsToSync.Followers.Select(x => x.FollowingsSyncStatus[userId]).ToList();
if (followingSyncStatuses.Count == 0)
{
_logger.LogWarning("No Followers sync found for {User}, Id: {UserId}", userWithTweetsToSync.User.Acct, userId);
return;
}
var lastPostedTweet = userWithTweetsToSync.Tweets.Select(x => x.Id).Max();
var minimumSync = followingSyncStatuses.Min();
var now = DateTime.UtcNow;
await _twitterUserDal.UpdateTwitterUserAsync(userId, lastPostedTweet, minimumSync, now);
}
catch (Exception e)
{
_logger.LogError(e, "SaveProgressionProcessor.ProcessAsync() Exception");
throw;
}
} }
} }
} }

View file

@ -87,7 +87,7 @@ namespace BirdsiteLive.Statistics.Domain
UserCallsCountMin = userCalls.Any() ? userCalls.Min() : 0, UserCallsCountMin = userCalls.Any() ? userCalls.Min() : 0,
UserCallsCountAvg = userCalls.Any() ? (int)userCalls.Average() : 0, UserCallsCountAvg = userCalls.Any() ? (int)userCalls.Average() : 0,
UserCallsCountMax = userCalls.Any() ? userCalls.Max() : 0, UserCallsCountMax = userCalls.Any() ? userCalls.Max() : 0,
UserCallsMax = 900, UserCallsMax = 300,
TweetCallsCountMin = tweetCalls.Any() ? tweetCalls.Min() : 0, TweetCallsCountMin = tweetCalls.Any() ? tweetCalls.Min() : 0,
TweetCallsCountAvg = tweetCalls.Any() ? (int)tweetCalls.Average() : 0, TweetCallsCountAvg = tweetCalls.Any() ? (int)tweetCalls.Average() : 0,
TweetCallsCountMax = tweetCalls.Any() ? tweetCalls.Max() : 0, TweetCallsCountMax = tweetCalls.Any() ? tweetCalls.Max() : 0,

View file

@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId> <UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Version>0.14.4</Version> <Version>0.14.5</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -33,6 +33,7 @@ namespace BirdsiteLive.Services
} }
finally finally
{ {
await Task.Delay(1000 * 30);
_applicationLifetime.StopApplication(); _applicationLifetime.StopApplication();
} }
} }

View file

@ -15,7 +15,7 @@
"AdminEmail": "me@domain.name", "AdminEmail": "me@domain.name",
"ResolveMentionsInProfiles": true, "ResolveMentionsInProfiles": true,
"PublishReplies": false, "PublishReplies": false,
"MaxUsersCapacity": 1400 "MaxUsersCapacity": 800
}, },
"Db": { "Db": {
"Type": "postgres", "Type": "postgres",

View file

@ -8,6 +8,7 @@ using BirdsiteLive.Pipeline.Models;
using BirdsiteLive.Pipeline.Processors; using BirdsiteLive.Pipeline.Processors;
using BirdsiteLive.Twitter.Models; using BirdsiteLive.Twitter.Models;
using Castle.DynamicProxy.Contributors; using Castle.DynamicProxy.Contributors;
using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq; using Moq;
@ -53,6 +54,8 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
}, },
User = user User = user
}; };
var loggerMock = new Mock<ILogger<SaveProgressionProcessor>>();
#endregion #endregion
#region Mocks #region Mocks
@ -67,11 +70,12 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
.Returns(Task.CompletedTask); .Returns(Task.CompletedTask);
#endregion #endregion
var processor = new SaveProgressionProcessor(twitterUserDalMock.Object); var processor = new SaveProgressionProcessor(twitterUserDalMock.Object, loggerMock.Object);
await processor.ProcessAsync(usersWithTweets, CancellationToken.None); await processor.ProcessAsync(usersWithTweets, CancellationToken.None);
#region Validations #region Validations
twitterUserDalMock.VerifyAll(); twitterUserDalMock.VerifyAll();
loggerMock.VerifyAll();
#endregion #endregion
} }
@ -129,13 +133,16 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
It.IsAny<DateTime>() It.IsAny<DateTime>()
)) ))
.Returns(Task.CompletedTask); .Returns(Task.CompletedTask);
var loggerMock = new Mock<ILogger<SaveProgressionProcessor>>();
#endregion #endregion
var processor = new SaveProgressionProcessor(twitterUserDalMock.Object); var processor = new SaveProgressionProcessor(twitterUserDalMock.Object, loggerMock.Object);
await processor.ProcessAsync(usersWithTweets, CancellationToken.None); await processor.ProcessAsync(usersWithTweets, CancellationToken.None);
#region Validations #region Validations
twitterUserDalMock.VerifyAll(); twitterUserDalMock.VerifyAll();
loggerMock.VerifyAll();
#endregion #endregion
} }
@ -201,13 +208,16 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
It.IsAny<DateTime>() It.IsAny<DateTime>()
)) ))
.Returns(Task.CompletedTask); .Returns(Task.CompletedTask);
var loggerMock = new Mock<ILogger<SaveProgressionProcessor>>();
#endregion #endregion
var processor = new SaveProgressionProcessor(twitterUserDalMock.Object); var processor = new SaveProgressionProcessor(twitterUserDalMock.Object, loggerMock.Object);
await processor.ProcessAsync(usersWithTweets, CancellationToken.None); await processor.ProcessAsync(usersWithTweets, CancellationToken.None);
#region Validations #region Validations
twitterUserDalMock.VerifyAll(); twitterUserDalMock.VerifyAll();
loggerMock.VerifyAll();
#endregion #endregion
} }
} }