Add lock and Fixes
This commit is contained in:
parent
0faf124bef
commit
5db3d3961f
@ -211,7 +211,7 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
|
||||
|
||||
model.Status = newStatus;
|
||||
|
||||
if (newStatus == OrderStatus.Выдан)
|
||||
if (model.Status == OrderStatus.Готов || element.Status == OrderStatus.Ожидание)
|
||||
{
|
||||
var plane = _planeStorage.GetElement(new PlaneSearchModel { Id = element.PlaneId });
|
||||
if (plane == null)
|
||||
@ -219,27 +219,22 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("Status change error. Plane not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CheckSupply(plane, element.Count))
|
||||
{
|
||||
_logger.LogWarning("Status change error. Shop is overflowed");
|
||||
|
||||
model.Status = OrderStatus.Ожидание;
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed");
|
||||
_logger.LogWarning("Status change error. Shop is overflowed");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
else
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
model.DateImplement = element.DateImplement;
|
||||
}
|
||||
|
||||
CheckModel(model, false);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
|
@ -27,6 +27,9 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
|
||||
/// </summary>
|
||||
private readonly Random _rnd;
|
||||
|
||||
private readonly object orderLock = new object();
|
||||
private readonly object waitingOrderLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Бизнес-логика для заказов
|
||||
/// </summary>
|
||||
@ -58,13 +61,8 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
|
||||
}
|
||||
|
||||
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят });
|
||||
if (orders == null || orders.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
||||
_logger.LogDebug("DoWork for {Count} orders", orders?.Count);
|
||||
foreach (var implementer in implementers)
|
||||
{
|
||||
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
||||
@ -96,16 +94,19 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
|
||||
{
|
||||
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
|
||||
// пытаемся назначить заказ на исполнителя
|
||||
lock (orderLock)
|
||||
{
|
||||
_orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
ImplementerId = implementer.Id
|
||||
});
|
||||
}
|
||||
|
||||
// делаем работу
|
||||
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
_orderLogic.DeliveryOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id
|
||||
});
|
||||
@ -155,7 +156,7 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
|
||||
// доделываем работу
|
||||
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
_orderLogic.DeliveryOrder(new OrderBindingModel
|
||||
{
|
||||
Id = runOrder.Id
|
||||
});
|
||||
@ -203,10 +204,13 @@ namespace AircraftPlantBusinessLogic.BusinessLogics
|
||||
foreach (var order in orders)
|
||||
{
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
lock (waitingOrderLock)
|
||||
{
|
||||
_orderLogic.DeliveryOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id
|
||||
});
|
||||
}
|
||||
|
||||
// отдыхаем
|
||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||
|
Loading…
Reference in New Issue
Block a user