mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:06:30 +00:00
fixed bugs with queue handling. At least most of them
This commit is contained in:
@@ -23,14 +23,22 @@ public class FailsafeAnnotationsProducer
|
||||
private readonly IDbFactory _dbFactory;
|
||||
private readonly IAzaionApi _azaionApi;
|
||||
private readonly QueueConfig _queueConfig;
|
||||
private readonly UIConfig _uiConfig;
|
||||
|
||||
private Producer _annotationProducer = null!;
|
||||
|
||||
public FailsafeAnnotationsProducer(ILogger<FailsafeAnnotationsProducer> logger, IDbFactory dbFactory, IOptions<QueueConfig> queueConfig, IAzaionApi azaionApi)
|
||||
|
||||
public FailsafeAnnotationsProducer(ILogger<FailsafeAnnotationsProducer> logger,
|
||||
IDbFactory dbFactory,
|
||||
IOptions<QueueConfig> queueConfig,
|
||||
IOptions<UIConfig> uiConfig,
|
||||
IAzaionApi azaionApi)
|
||||
{
|
||||
_logger = logger;
|
||||
_dbFactory = dbFactory;
|
||||
_azaionApi = azaionApi;
|
||||
_queueConfig = queueConfig.Value;
|
||||
_uiConfig = uiConfig.Value;
|
||||
Task.Run(async () => await ProcessQueue());
|
||||
}
|
||||
|
||||
@@ -71,7 +79,7 @@ public class FailsafeAnnotationsProducer
|
||||
{
|
||||
var appProperties = new ApplicationProperties
|
||||
{
|
||||
{ nameof(AnnotationStatus), record.Operation },
|
||||
{ nameof(AnnotationStatus), record.Operation.ToString() },
|
||||
{ nameof(User.Email), _azaionApi.CurrentUser.Email }
|
||||
};
|
||||
|
||||
@@ -86,7 +94,7 @@ public class FailsafeAnnotationsProducer
|
||||
}
|
||||
else
|
||||
{
|
||||
var annotation = annotationsDict.GetValueOrDefault(record.AnnotationNames.FirstOrDefault());
|
||||
var annotation = annotationsDict!.GetValueOrDefault(record.AnnotationNames.FirstOrDefault());
|
||||
if (annotation == null)
|
||||
continue;
|
||||
|
||||
@@ -118,7 +126,8 @@ public class FailsafeAnnotationsProducer
|
||||
if (result.messages.Any())
|
||||
{
|
||||
await _annotationProducer.Send(result.messages, CompressionType.Gzip);
|
||||
await _dbFactory.Run(async db => await db.DeleteAsync(result.records, token: ct));
|
||||
var ids = result.records.Select(x => x.Id).ToList();
|
||||
var removed = await _dbFactory.Run(async db => await db.AnnotationsQueueRecords.DeleteAsync(x => ids.Contains(x.Id), token: ct));
|
||||
sent = true;
|
||||
_dbFactory.SaveToDisk();
|
||||
}
|
||||
@@ -136,9 +145,12 @@ public class FailsafeAnnotationsProducer
|
||||
|
||||
public async Task SendToInnerQueue(List<string> annotationNames, AnnotationStatus status, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_uiConfig.SilentDetection)
|
||||
return;
|
||||
await _dbFactory.Run(async db =>
|
||||
await db.InsertAsync(new AnnotationQueueRecord
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
DateTime = DateTime.UtcNow,
|
||||
Operation = status,
|
||||
AnnotationNames = annotationNames
|
||||
|
||||
Reference in New Issue
Block a user