Merge pull request #16335 from abpframework/auto-merge/rel-7-2/1882

Merge branch dev with rel-7.2
pull/16351/head
Halil İbrahim Kalkan 3 years ago committed by GitHub
commit b30d14be80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -133,7 +133,14 @@ public class AbpFeatureManagementDomainModule : AbpModule
await Policy
.Handle<Exception>()
.WaitAndRetryAsync(8, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt) * 10))
.WaitAndRetryAsync(
8,
retryAttempt => TimeSpan.FromSeconds(
RandomHelper.GetRandom(
(int)Math.Pow(2, retryAttempt) * 8,
(int)Math.Pow(2, retryAttempt) * 12)
)
)
.ExecuteAsync(async _ =>
{
try

@ -27,6 +27,8 @@ public class StaticFeatureSaver : IStaticFeatureSaver, ITransientDependency
protected AbpFeatureOptions FeatureOptions { get; }
protected ICancellationTokenProvider CancellationTokenProvider { get; }
protected AbpDistributedCacheOptions CacheOptions { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; }
public StaticFeatureSaver(
IStaticFeatureDefinitionStore staticStore,
@ -38,7 +40,8 @@ public class StaticFeatureSaver : IStaticFeatureSaver, ITransientDependency
IApplicationInfoAccessor applicationInfoAccessor,
IAbpDistributedLock distributedLock,
IOptions<AbpFeatureOptions> featureManagementOptions,
ICancellationTokenProvider cancellationTokenProvider)
ICancellationTokenProvider cancellationTokenProvider,
IUnitOfWorkManager unitOfWorkManager)
{
StaticStore = staticStore;
FeatureGroupRepository = featureGroupRepository;
@ -48,12 +51,12 @@ public class StaticFeatureSaver : IStaticFeatureSaver, ITransientDependency
ApplicationInfoAccessor = applicationInfoAccessor;
DistributedLock = distributedLock;
CancellationTokenProvider = cancellationTokenProvider;
UnitOfWorkManager = unitOfWorkManager;
FeatureOptions = featureManagementOptions.Value;
CacheOptions = cacheOptions.Value;
}
[UnitOfWork]
public virtual async Task SaveAsync()
public async Task SaveAsync()
{
await using var applicationLockHandle = await DistributedLock.TryAcquireAsync(
GetApplicationDistributedLockKey()
@ -99,19 +102,40 @@ public class StaticFeatureSaver : IStaticFeatureSaver, ITransientDependency
throw new AbpException("Could not acquire distributed lock for saving static features!");
}
var hasChangesInGroups = await UpdateChangedFeatureGroupsAsync(featureGroupRecords);
var hasChangesInFeatures = await UpdateChangedFeaturesAsync(featureRecords);
if (hasChangesInGroups ||hasChangesInFeatures)
using (var unitOfWork = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
{
await Cache.SetStringAsync(
GetCommonStampCacheKey(),
Guid.NewGuid().ToString(),
new DistributedCacheEntryOptions {
SlidingExpiration = TimeSpan.FromDays(30) //TODO: Make it configurable?
},
CancellationTokenProvider.Token
);
try
{
var hasChangesInGroups = await UpdateChangedFeatureGroupsAsync(featureGroupRecords);
var hasChangesInFeatures = await UpdateChangedFeaturesAsync(featureRecords);
if (hasChangesInGroups ||hasChangesInFeatures)
{
await Cache.SetStringAsync(
GetCommonStampCacheKey(),
Guid.NewGuid().ToString(),
new DistributedCacheEntryOptions {
SlidingExpiration = TimeSpan.FromDays(30) //TODO: Make it configurable?
},
CancellationTokenProvider.Token
);
}
}
catch
{
try
{
await unitOfWork.RollbackAsync();
}
catch
{
/* ignored */
}
throw;
}
await unitOfWork.CompleteAsync();
}
}

@ -118,7 +118,14 @@ public class AbpPermissionManagementDomainModule : AbpModule
await Policy
.Handle<Exception>()
.WaitAndRetryAsync(8, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt) * 10))
.WaitAndRetryAsync(
8,
retryAttempt => TimeSpan.FromSeconds(
RandomHelper.GetRandom(
(int)Math.Pow(2, retryAttempt) * 8,
(int)Math.Pow(2, retryAttempt) * 12)
)
)
.ExecuteAsync(async _ =>
{
try

@ -28,6 +28,8 @@ public class StaticPermissionSaver : IStaticPermissionSaver, ITransientDependenc
protected ICancellationTokenProvider CancellationTokenProvider { get; }
protected AbpDistributedCacheOptions CacheOptions { get; }
protected IUnitOfWorkManager UnitOfWorkManager { get; }
public StaticPermissionSaver(
IStaticPermissionDefinitionStore staticStore,
IPermissionGroupDefinitionRecordRepository permissionGroupRepository,
@ -38,8 +40,10 @@ public class StaticPermissionSaver : IStaticPermissionSaver, ITransientDependenc
IApplicationInfoAccessor applicationInfoAccessor,
IAbpDistributedLock distributedLock,
IOptions<AbpPermissionOptions> permissionOptions,
ICancellationTokenProvider cancellationTokenProvider)
ICancellationTokenProvider cancellationTokenProvider,
IUnitOfWorkManager unitOfWorkManager)
{
UnitOfWorkManager = unitOfWorkManager;
StaticStore = staticStore;
PermissionGroupRepository = permissionGroupRepository;
PermissionRepository = permissionRepository;
@ -52,8 +56,7 @@ public class StaticPermissionSaver : IStaticPermissionSaver, ITransientDependenc
CacheOptions = cacheOptions.Value;
}
[UnitOfWork]
public virtual async Task SaveAsync()
public async Task SaveAsync()
{
await using var applicationLockHandle = await DistributedLock.TryAcquireAsync(
GetApplicationDistributedLockKey()
@ -99,19 +102,40 @@ public class StaticPermissionSaver : IStaticPermissionSaver, ITransientDependenc
throw new AbpException("Could not acquire distributed lock for saving static permissions!");
}
var hasChangesInGroups = await UpdateChangedPermissionGroupsAsync(permissionGroupRecords);
var hasChangesInPermissions = await UpdateChangedPermissionsAsync(permissionRecords);
if (hasChangesInGroups ||hasChangesInPermissions)
using (var unitOfWork = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
{
await Cache.SetStringAsync(
GetCommonStampCacheKey(),
Guid.NewGuid().ToString(),
new DistributedCacheEntryOptions {
SlidingExpiration = TimeSpan.FromDays(30) //TODO: Make it configurable?
},
CancellationTokenProvider.Token
);
try
{
var hasChangesInGroups = await UpdateChangedPermissionGroupsAsync(permissionGroupRecords);
var hasChangesInPermissions = await UpdateChangedPermissionsAsync(permissionRecords);
if (hasChangesInGroups || hasChangesInPermissions)
{
await Cache.SetStringAsync(
GetCommonStampCacheKey(),
Guid.NewGuid().ToString(),
new DistributedCacheEntryOptions {
SlidingExpiration = TimeSpan.FromDays(30) //TODO: Make it configurable?
},
CancellationTokenProvider.Token
);
}
}
catch
{
try
{
await unitOfWork.RollbackAsync();
}
catch
{
/* ignored */
}
throw;
}
await unitOfWork.CompleteAsync();
}
}
@ -136,7 +160,8 @@ public class StaticPermissionSaver : IStaticPermissionSaver, ITransientDependenc
foreach (var permissionGroupRecord in permissionGroupRecords)
{
var permissionGroupRecordInDatabase = permissionGroupRecordsInDatabase.GetOrDefault(permissionGroupRecord.Name);
var permissionGroupRecordInDatabase =
permissionGroupRecordsInDatabase.GetOrDefault(permissionGroupRecord.Name);
if (permissionGroupRecordInDatabase == null)
{
/* New group */
@ -291,4 +316,4 @@ public class StaticPermissionSaver : IStaticPermissionSaver, ITransientDependenc
.ToString()
.ToMd5();
}
}
}
Loading…
Cancel
Save