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
parent
commit
d672709584
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs
  2. 8
      plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Plugins.Inventories.OrleansGrains/EasyAbp/EShop/Plugins/Inventories/OrleansGrains/InventoryGrain.cs

8
plugins/Inventories/DaprActors/src/EasyAbp.EShop.Plugins.Inventories.DaprActors/EasyAbp/EShop/Plugins/Inventories/DaprActors/InventoryActor.cs

@ -39,7 +39,7 @@ public class InventoryActor : Actor, IInventoryActor
} }
else else
{ {
await TryRegisterFlashSalesPersistInventoryTimerAsync(); await TryStartIntervalPersistInventoryAsync();
} }
} }
@ -55,11 +55,11 @@ public class InventoryActor : Actor, IInventoryActor
} }
else else
{ {
await TryRegisterFlashSalesPersistInventoryTimerAsync(); await TryStartIntervalPersistInventoryAsync();
} }
} }
protected virtual async Task TryRegisterFlashSalesPersistInventoryTimerAsync() protected virtual async Task TryStartIntervalPersistInventoryAsync()
{ {
if (FlashSalesInventoryUpdated) if (FlashSalesInventoryUpdated)
{ {
@ -68,6 +68,8 @@ public class InventoryActor : Actor, IInventoryActor
FlashSalesInventoryUpdated = true; FlashSalesInventoryUpdated = true;
await SetInventoryStateAsync(await GetInventoryStateAsync());
await RegisterTimerAsync(null, nameof(TimerSetInventoryStateAsync), null, TimeSpan.FromSeconds(5), await RegisterTimerAsync(null, nameof(TimerSetInventoryStateAsync), null, TimeSpan.FromSeconds(5),
TimeSpan.FromMilliseconds(-1)); TimeSpan.FromMilliseconds(-1));
} }

8
plugins/Inventories/OrleansGrains/src/EasyAbp.EShop.Plugins.Inventories.OrleansGrains/EasyAbp/EShop/Plugins/Inventories/OrleansGrains/InventoryGrain.cs

@ -25,7 +25,7 @@ public class InventoryGrain : Grain<InventoryStateModel>, IInventoryGrain
} }
else else
{ {
TryRegisterFlashSalesPersistInventoryTimer(); await TryStartIntervalPersistInventoryAsync();
} }
} }
@ -39,11 +39,11 @@ public class InventoryGrain : Grain<InventoryStateModel>, IInventoryGrain
} }
else else
{ {
TryRegisterFlashSalesPersistInventoryTimer(); await TryStartIntervalPersistInventoryAsync();
} }
} }
protected virtual void TryRegisterFlashSalesPersistInventoryTimer() protected virtual async Task TryStartIntervalPersistInventoryAsync()
{ {
if (FlashSalesInventoryUpdated) if (FlashSalesInventoryUpdated)
{ {
@ -52,6 +52,8 @@ public class InventoryGrain : Grain<InventoryStateModel>, IInventoryGrain
FlashSalesInventoryUpdated = true; FlashSalesInventoryUpdated = true;
await WriteStateAsync();
RegisterTimer(TimerWriteInventoryStateAsync, new object(), TimeSpan.FromSeconds(5), RegisterTimer(TimerWriteInventoryStateAsync, new object(), TimeSpan.FromSeconds(5),
TimeSpan.FromMilliseconds(-1)); TimeSpan.FromMilliseconds(-1));
} }

Loading…
Cancel
Save