2023-01-06 07:50:45 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-01-06 08:52:23 +01:00
|
|
|
|
using BirdsiteLive.Common.Settings;
|
2023-01-06 07:50:45 +01:00
|
|
|
|
using BirdsiteLive.DAL.Contracts;
|
|
|
|
|
using BirdsiteLive.Pipeline.Contracts.TweetsCleanUp;
|
|
|
|
|
using BirdsiteLive.Pipeline.Models;
|
2023-01-06 08:52:23 +01:00
|
|
|
|
using BirdsiteLive.Pipeline.Processors.TweetsCleanUp.Base;
|
2023-01-06 07:50:45 +01:00
|
|
|
|
|
|
|
|
|
namespace BirdsiteLive.Pipeline.Processors.TweetsCleanUp
|
2023-01-06 06:28:45 +01:00
|
|
|
|
{
|
2023-01-06 08:52:23 +01:00
|
|
|
|
public class SaveDeletedTweetStatusProcessor : RetentionBase, ISaveDeletedTweetStatusProcessor
|
2023-01-06 06:28:45 +01:00
|
|
|
|
{
|
2023-01-06 07:50:45 +01:00
|
|
|
|
private readonly ISyncTweetsPostgresDal _syncTweetsPostgresDal;
|
2023-01-06 08:52:23 +01:00
|
|
|
|
private readonly InstanceSettings _instanceSettings;
|
2023-01-06 07:50:45 +01:00
|
|
|
|
|
|
|
|
|
#region Ctor
|
2023-01-06 08:52:23 +01:00
|
|
|
|
public SaveDeletedTweetStatusProcessor(ISyncTweetsPostgresDal syncTweetsPostgresDal, InstanceSettings instanceSettings)
|
2023-01-06 07:50:45 +01:00
|
|
|
|
{
|
|
|
|
|
_syncTweetsPostgresDal = syncTweetsPostgresDal;
|
2023-01-06 08:52:23 +01:00
|
|
|
|
_instanceSettings = instanceSettings;
|
2023-01-06 07:50:45 +01:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public async Task ProcessAsync(TweetToDelete tweetToDelete, CancellationToken ct)
|
|
|
|
|
{
|
2023-01-06 08:52:23 +01:00
|
|
|
|
var retentionTime = GetRetentionTime(_instanceSettings);
|
|
|
|
|
retentionTime += 20; // Delay until last retry
|
|
|
|
|
var highLimitDate = DateTime.UtcNow.AddDays(-retentionTime);
|
2023-01-06 07:50:45 +01:00
|
|
|
|
if (tweetToDelete.DeleteSuccessful || tweetToDelete.Tweet.PublishedAt < highLimitDate)
|
|
|
|
|
{
|
|
|
|
|
await _syncTweetsPostgresDal.DeleteTweetAsync(tweetToDelete.Tweet.Id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-06 06:28:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|