mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-18 09:52:11 +08:00
commit
5cb5dad0ac
@ -58,16 +58,16 @@ public class PersistMessageDbContext : DbContext, IPersistMessageDbContext
|
|||||||
{
|
{
|
||||||
foreach (var entry in ex.Entries)
|
foreach (var entry in ex.Entries)
|
||||||
{
|
{
|
||||||
var currentValues = entry.CurrentValues;
|
|
||||||
var databaseValues = await entry.GetDatabaseValuesAsync(cancellationToken);
|
var databaseValues = await entry.GetDatabaseValuesAsync(cancellationToken);
|
||||||
|
|
||||||
_logger.LogInformation(
|
if (databaseValues == null)
|
||||||
"Entry to entity with database-value: {@databaseValues} and current-value: {@currentValues}",
|
{
|
||||||
databaseValues,
|
_logger.LogError("The record no longer exists in the database, The record has been deleted by another user.");
|
||||||
currentValues);
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
// Refresh the original values with current values
|
// Refresh the original values to bypass next concurrency check
|
||||||
entry.OriginalValues.SetValues(currentValues);
|
entry.OriginalValues.SetValues(databaseValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await base.SaveChangesAsync(cancellationToken);
|
return await base.SaveChangesAsync(cancellationToken);
|
||||||
|
|||||||
@ -18,6 +18,7 @@ public class PersistMessageProcessor : IPersistMessageProcessor
|
|||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
private readonly IPersistMessageDbContext _persistMessageDbContext;
|
private readonly IPersistMessageDbContext _persistMessageDbContext;
|
||||||
private readonly IPublishEndpoint _publishEndpoint;
|
private readonly IPublishEndpoint _publishEndpoint;
|
||||||
|
private SemaphoreSlim Semaphore => new SemaphoreSlim(1);
|
||||||
|
|
||||||
public PersistMessageProcessor(
|
public PersistMessageProcessor(
|
||||||
ILogger<PersistMessageProcessor> logger,
|
ILogger<PersistMessageProcessor> logger,
|
||||||
@ -115,7 +116,19 @@ public class PersistMessageProcessor : IPersistMessageProcessor
|
|||||||
.Where(x => x.MessageStatus != MessageStatus.Processed)
|
.Where(x => x.MessageStatus != MessageStatus.Processed)
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
foreach (var message in messages) await ProcessAsync(message.Id, message.DeliveryType, cancellationToken);
|
foreach (var message in messages)
|
||||||
|
{
|
||||||
|
await Semaphore.WaitAsync(cancellationToken);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await ProcessAsync(message.Id, message.DeliveryType, cancellationToken);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Semaphore.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ProcessInboxAsync(long messageId, CancellationToken cancellationToken = default)
|
public async Task ProcessInboxAsync(long messageId, CancellationToken cancellationToken = default)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user