Fix#228: Add Redis distributed lock provider (#330)

* Fix#325:Elsa 2#RunWorkflowDefinitionAsync getting object reference null

* Fix#328: Rephrased error message

* activityId should not be mandatory while using RunWorkflowDefinitionAsync

* Fix#228:Add Redis distributed lock provider

* Removed unnecessary namespaces

* Fix#228: Add Redis distributed lock provider, Re-architeched the soultion which includes
 - Remove of StartAsync
 - Auto Recover of Transient error

* Fix#228: Add Redis distributed lock provider, This includes below enhqncement
 - Better Log Management,
 -  Return false instead of throwing error in while unable to acquire lock

* Fix#228: Merge Conflict

* Fix#228: Solving Merge Conflict

* Fix#Merge Conflict

* Fix#228: Add Redis distributed lock provider #330 - Merge Conflict

* Fix#228: Add Redis distributed lock provider, Updated Log message as suggested in PR#332

Co-authored-by: Ankit Sarkar <ankt.srkr@live.in>
This commit is contained in:
Ankit Sarkar 2020-07-15 15:22:53 +05:30 committed by GitHub
parent 02cad73af0
commit b408b33c33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View file

@ -238,6 +238,7 @@ Global
{E20238CE-5C64-4F87-8753-3B4E1EC9A740}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E20238CE-5C64-4F87-8753-3B4E1EC9A740}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E20238CE-5C64-4F87-8753-3B4E1EC9A740}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -34,7 +34,7 @@ namespace Elsa.DistributedLocking.Redis
private async Task<bool> CreateLockAsync(string name, CancellationToken cancellationToken = default)
{
var resourceName = $"{Prefix}:{name}";
_logger.LogInformation($"Lock provider will try to acquire lock for {resourceName}");
_logger.LogInformation("Lock provider will try to acquire lock for {resourceName}",resourceName);
try
{
var redLock = await _distributedLockFactory.CreateLockAsync(resourceName, _lockTimeout,
@ -50,7 +50,7 @@ namespace Elsa.DistributedLocking.Redis
{
RedLockInstance.Add(redLock);
}
_logger.LogInformation($"Lock provider acquired lock for {resourceName}");
_logger.LogInformation("Lock provider acquired lock for {resourceName}",resourceName);
return true;
}
@ -58,7 +58,7 @@ namespace Elsa.DistributedLocking.Redis
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to acquire lock for {resourceName}. Reason > {ex}");
_logger.LogWarning("Failed to acquire lock for {resourceName}. Reason > {ex}",resourceName,ex);
return false;
}
}
@ -71,7 +71,8 @@ namespace Elsa.DistributedLocking.Redis
}
var resourceName = $"{Prefix}:{name}";
_logger.LogInformation($"Lock provider will try to release lock for {resourceName}");
_logger.LogInformation("Lock provider will try to release lock for {resourceName}", resourceName);
try
{
lock (RedLockInstance)
@ -82,7 +83,8 @@ namespace Elsa.DistributedLocking.Redis
{
redLock.Dispose();
RedLockInstance.Remove(redLock);
_logger.LogInformation($"Lock provider released lock for {resourceName}");
_logger.LogInformation("Lock provider released lock for {resourceName}",resourceName);
break;
}
}
@ -90,7 +92,7 @@ namespace Elsa.DistributedLocking.Redis
}
catch (Exception ex)
{
_logger.LogWarning($"Failed to release lock for {resourceName}. Reason > {ex}");
_logger.LogWarning("Failed to release lock for {resourceName}. Reason > {ex}",resourceName,ex);
}
return Task.CompletedTask;
}

View file

@ -12,7 +12,7 @@ namespace Elsa.Samples.DistributedLock
{
private static async Task Main()
{
await CreateHostBuilder().UseConsoleLifetime().Build().RunAsync();
await CreateHostBuilder().UseConsoleLifetime().Build().RunAsync();
}
public static IHostBuilder CreateHostBuilder() =>