Browse Source
Merge pull request #219 from EasyAbp/persist-inventory-immediately
Persist inventory immediately for the first time invoking
pull/222/head
Super
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
10 additions and
6 deletions
-
plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs
-
plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Plugins.Inventories.OrleansGrains/EasyAbp/EShop/Plugins/Inventories/OrleansGrains/InventoryGrain.cs
|
|
|
@ -39,7 +39,7 @@ public class InventoryActor : Actor, IInventoryActor |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
await TryRegisterFlashSalesPersistInventoryTimerAsync(); |
|
|
|
await TryStartIntervalPersistInventoryAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -55,11 +55,11 @@ public class InventoryActor : Actor, IInventoryActor |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
await TryRegisterFlashSalesPersistInventoryTimerAsync(); |
|
|
|
await TryStartIntervalPersistInventoryAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task TryRegisterFlashSalesPersistInventoryTimerAsync() |
|
|
|
protected virtual async Task TryStartIntervalPersistInventoryAsync() |
|
|
|
{ |
|
|
|
if (FlashSalesInventoryUpdated) |
|
|
|
{ |
|
|
|
@ -68,6 +68,8 @@ public class InventoryActor : Actor, IInventoryActor |
|
|
|
|
|
|
|
FlashSalesInventoryUpdated = true; |
|
|
|
|
|
|
|
await SetInventoryStateAsync(await GetInventoryStateAsync()); |
|
|
|
|
|
|
|
await RegisterTimerAsync(null, nameof(TimerSetInventoryStateAsync), null, TimeSpan.FromSeconds(5), |
|
|
|
TimeSpan.FromMilliseconds(-1)); |
|
|
|
} |
|
|
|
|
|
|
|
@ -25,7 +25,7 @@ public class InventoryGrain : Grain<InventoryStateModel>, IInventoryGrain |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
TryRegisterFlashSalesPersistInventoryTimer(); |
|
|
|
await TryStartIntervalPersistInventoryAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -39,11 +39,11 @@ public class InventoryGrain : Grain<InventoryStateModel>, IInventoryGrain |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
TryRegisterFlashSalesPersistInventoryTimer(); |
|
|
|
await TryStartIntervalPersistInventoryAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual void TryRegisterFlashSalesPersistInventoryTimer() |
|
|
|
protected virtual async Task TryStartIntervalPersistInventoryAsync() |
|
|
|
{ |
|
|
|
if (FlashSalesInventoryUpdated) |
|
|
|
{ |
|
|
|
@ -52,6 +52,8 @@ public class InventoryGrain : Grain<InventoryStateModel>, IInventoryGrain |
|
|
|
|
|
|
|
FlashSalesInventoryUpdated = true; |
|
|
|
|
|
|
|
await WriteStateAsync(); |
|
|
|
|
|
|
|
RegisterTimer(TimerWriteInventoryStateAsync, new object(), TimeSpan.FromSeconds(5), |
|
|
|
TimeSpan.FromMilliseconds(-1)); |
|
|
|
} |
|
|
|
|