diff --git a/src/BirdsiteLive.Pipeline/Processors/RetrieveTweetsProcessor.cs b/src/BirdsiteLive.Pipeline/Processors/RetrieveTweetsProcessor.cs index c0976c5..e60c121 100644 --- a/src/BirdsiteLive.Pipeline/Processors/RetrieveTweetsProcessor.cs +++ b/src/BirdsiteLive.Pipeline/Processors/RetrieveTweetsProcessor.cs @@ -17,12 +17,12 @@ namespace BirdsiteLive.Pipeline.Processors public class RetrieveTweetsProcessor : IRetrieveTweetsProcessor { private readonly ITwitterTweetsService _twitterTweetsService; - private readonly ITwitterUserService _twitterUserService; + private readonly ICachedTwitterUserService _twitterUserService; private readonly ITwitterUserDal _twitterUserDal; private readonly ILogger _logger; #region Ctor - public RetrieveTweetsProcessor(ITwitterTweetsService twitterTweetsService, ITwitterUserDal twitterUserDal, ITwitterUserService twitterUserService, ILogger logger) + public RetrieveTweetsProcessor(ITwitterTweetsService twitterTweetsService, ITwitterUserDal twitterUserDal, ICachedTwitterUserService twitterUserService, ILogger logger) { _twitterTweetsService = twitterTweetsService; _twitterUserDal = twitterUserDal; @@ -77,13 +77,8 @@ namespace BirdsiteLive.Pipeline.Processors } catch (Exception e) { - _logger.LogError(e, "Error retrieving TL of {Username} from {LastTweetPostedId}", user.Acct, user.LastTweetPostedId); - - if (_twitterUserService is CachedTwitterUserService service) - { - _logger.LogInformation("Purge {Username} from cache", user.Acct); - service.PurgeUser(user.Acct); - } + _logger.LogError(e, "Error retrieving TL of {Username} from {LastTweetPostedId}, purging user from cache", user.Acct, user.LastTweetPostedId); + _twitterUserService.PurgeUser(user.Acct); } return tweets; diff --git a/src/BirdsiteLive.Twitter/CachedTwitterService.cs b/src/BirdsiteLive.Twitter/CachedTwitterService.cs index d8ca1fb..d9b90d2 100644 --- a/src/BirdsiteLive.Twitter/CachedTwitterService.cs +++ b/src/BirdsiteLive.Twitter/CachedTwitterService.cs @@ -4,7 +4,12 @@ using Microsoft.Extensions.Caching.Memory; namespace BirdsiteLive.Twitter { - public class CachedTwitterUserService : ITwitterUserService + public interface ICachedTwitterUserService : ITwitterUserService + { + void PurgeUser(string username); + } + + public class CachedTwitterUserService : ICachedTwitterUserService { private readonly ITwitterUserService _twitterService; diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/BirdsiteLive.Pipeline.Tests.csproj b/src/Tests/BirdsiteLive.Pipeline.Tests/BirdsiteLive.Pipeline.Tests.csproj index aa7750b..d1cfd06 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/BirdsiteLive.Pipeline.Tests.csproj +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/BirdsiteLive.Pipeline.Tests.csproj @@ -14,12 +14,14 @@ - - - - + + + + + + diff --git a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTweetsProcessorTests.cs b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTweetsProcessorTests.cs index b35a688..02fd7bd 100644 --- a/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTweetsProcessorTests.cs +++ b/src/Tests/BirdsiteLive.Pipeline.Tests/Processors/RetrieveTweetsProcessorTests.cs @@ -61,7 +61,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors )) .Returns(Task.CompletedTask); - var twitterUserServiceMock = new Mock(MockBehavior.Strict); + var twitterUserServiceMock = new Mock(MockBehavior.Strict); var logger = new Mock>(MockBehavior.Strict); #endregion @@ -125,7 +125,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors var twitterUserDalMock = new Mock(MockBehavior.Strict); - var twitterUserServiceMock = new Mock(MockBehavior.Strict); + var twitterUserServiceMock = new Mock(MockBehavior.Strict); var logger = new Mock>(MockBehavior.Strict); #endregion @@ -192,7 +192,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors var twitterUserDalMock = new Mock(MockBehavior.Strict); - var twitterUserServiceMock = new Mock(MockBehavior.Strict); + var twitterUserServiceMock = new Mock(MockBehavior.Strict); var logger = new Mock>(MockBehavior.Strict); #endregion