Fix LogPersistenceMode default mapping logic (#5218)
* Fix LogPersistenceMode default mapping logic Fixes #5217 * Format adjustment in DefaultActivityExecutionMapper.cs Applied minor code reformatting in the DefaultActivityExecutionMapper.cs file to maintain consistency and improve readability. This was mostly centered around adding spaces for proper code alignment and indentation to match the overall code style in the project. No functional changes were made.
This commit is contained in:
parent
9f55e831e6
commit
8bcab1b832
|
|
@ -18,6 +18,7 @@ using Elsa.MongoDb.Modules.Identity;
|
|||
using Elsa.MongoDb.Modules.Management;
|
||||
using Elsa.MongoDb.Modules.Runtime;
|
||||
using Elsa.Server.Web;
|
||||
using Elsa.Workflows.Enums;
|
||||
using Elsa.Workflows.Management.Compression;
|
||||
using Elsa.Workflows.Management.Stores;
|
||||
using Elsa.Workflows.Runtime.Stores;
|
||||
|
|
@ -154,6 +155,8 @@ services
|
|||
|
||||
if (useCachingStores)
|
||||
management.UseCachingStores();
|
||||
|
||||
management.SetDefaultLogPersistenceMode(LogPersistenceMode.Default);
|
||||
})
|
||||
.UseWorkflowRuntime(runtime =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,39 +11,27 @@ using Microsoft.Extensions.Options;
|
|||
namespace Elsa.Workflows.Runtime.Services;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class DefaultActivityExecutionMapper : IActivityExecutionMapper
|
||||
{
|
||||
private LogPersistenceMode _serverLogPersistenceMode;
|
||||
private const string LogPersistenceModeKey = "logPersistenceMode";
|
||||
|
||||
public DefaultActivityExecutionMapper(IOptions<ManagementOptions> options)
|
||||
{
|
||||
_serverLogPersistenceMode = options.Value.LogPersistenceMode;
|
||||
}
|
||||
|
||||
public class DefaultActivityExecutionMapper(IOptions<ManagementOptions> options) : IActivityExecutionMapper
|
||||
{
|
||||
private const string LogPersistenceModeKey = "logPersistenceMode";
|
||||
|
||||
/// <inheritdoc />
|
||||
public ActivityExecutionRecord Map(ActivityExecutionContext source)
|
||||
{
|
||||
/*
|
||||
* {
|
||||
* "logPersistenceMode": {
|
||||
* "default": "default",
|
||||
* "inputs": { k : v },
|
||||
* "outputs": { k: v }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
var workflowPersistenceProperty =
|
||||
GetDefaultPersistenceMode(source.WorkflowExecutionContext.Workflow.CustomProperties, () => _serverLogPersistenceMode);
|
||||
|
||||
|
||||
var activityPersistenceProperties = source.Activity.CustomProperties
|
||||
.GetValueOrDefault<IDictionary<string, object?>>(LogPersistenceModeKey, () => new Dictionary<string, object?>());
|
||||
var activityPersistencePropertyDefault =
|
||||
GetDefaultPersistenceMode(source.Activity.CustomProperties, () => workflowPersistenceProperty);
|
||||
|
||||
|
||||
{
|
||||
/*
|
||||
* {
|
||||
* "logPersistenceMode": {
|
||||
* "default": "default",
|
||||
* "inputs": { k : v },
|
||||
* "outputs": { k: v }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
var workflowPersistenceProperty = GetDefaultPersistenceMode(source.WorkflowExecutionContext.Workflow.CustomProperties, () => options.Value.LogPersistenceMode);
|
||||
var activityPersistenceProperties = source.Activity.CustomProperties.GetValueOrDefault<IDictionary<string, object?>>(LogPersistenceModeKey, () => new Dictionary<string, object?>());
|
||||
var activityPersistencePropertyDefault = GetDefaultPersistenceMode(source.Activity.CustomProperties, () => workflowPersistenceProperty);
|
||||
|
||||
// Get any outcomes that were added to the activity execution context.
|
||||
var outcomes = source.JournalData.TryGetValue("Outcomes", out var resultValue) ? resultValue as string[] : default;
|
||||
var payload = new Dictionary<string, object>();
|
||||
|
|
@ -72,10 +60,10 @@ public class DefaultActivityExecutionMapper : IActivityExecutionMapper
|
|||
|
||||
return default;
|
||||
});
|
||||
|
||||
outputs = StorePropertyUsingPersistanceMode(outputs, activityPersistenceProperties!.GetValueOrDefault("outputs", () => new Dictionary<string, object>())!, activityPersistencePropertyDefault);
|
||||
var activityState = StorePropertyUsingPersistanceMode(source.ActivityState, activityPersistenceProperties!.GetValueOrDefault("inputs", () => new Dictionary<string, object>())!, activityPersistencePropertyDefault );
|
||||
|
||||
|
||||
outputs = StorePropertyUsingPersistenceMode(outputs, activityPersistenceProperties!.GetValueOrDefault("outputs", () => new Dictionary<string, object>())!, activityPersistencePropertyDefault);
|
||||
var activityState = StorePropertyUsingPersistenceMode(source.ActivityState, activityPersistenceProperties!.GetValueOrDefault("inputs", () => new Dictionary<string, object>())!, activityPersistencePropertyDefault);
|
||||
|
||||
return new ActivityExecutionRecord
|
||||
{
|
||||
Id = source.Id,
|
||||
|
|
@ -95,39 +83,35 @@ public class DefaultActivityExecutionMapper : IActivityExecutionMapper
|
|||
Status = GetAggregateStatus(source),
|
||||
CompletedAt = source.CompletedAt
|
||||
};
|
||||
}
|
||||
|
||||
private static LogPersistenceMode GetDefaultPersistenceMode(IDictionary<string, object> customProperties,Func<LogPersistenceMode> defaultFactory)
|
||||
{
|
||||
var properties = customProperties
|
||||
.GetValueOrDefault<IDictionary<string, object?>>(LogPersistenceModeKey, () => new Dictionary<string, object?>());
|
||||
var persistencePropertyDefault = properties!
|
||||
.GetValueOrDefault("default", defaultFactory);
|
||||
|
||||
if(persistencePropertyDefault == LogPersistenceMode.Default)
|
||||
return defaultFactory();
|
||||
return persistencePropertyDefault;
|
||||
}
|
||||
|
||||
private static Dictionary<string,object?> StorePropertyUsingPersistanceMode(IDictionary<string,object?> inputs
|
||||
, IDictionary<string,object> persistenceModeConfiguration
|
||||
, LogPersistenceMode defaultLogPersistenceMode = LogPersistenceMode.Exclude)
|
||||
{
|
||||
var result = new Dictionary<string, object?>();
|
||||
|
||||
foreach (var input in inputs)
|
||||
{
|
||||
var persistence = persistenceModeConfiguration.GetValueOrDefault(input.Key.Camelize(), () => defaultLogPersistenceMode);
|
||||
if (persistence.Equals(LogPersistenceMode.Include)
|
||||
|| (persistence.Equals(LogPersistenceMode.Default) && defaultLogPersistenceMode == LogPersistenceMode.Include)
|
||||
)
|
||||
result.Add(input.Key, input.Value);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static LogPersistenceMode GetDefaultPersistenceMode(IDictionary<string, object> customProperties, Func<LogPersistenceMode> defaultFactory)
|
||||
{
|
||||
var properties = customProperties.GetValueOrDefault<IDictionary<string, object?>>(LogPersistenceModeKey, () => new Dictionary<string, object?>());
|
||||
var persistencePropertyDefault = properties!.GetValueOrDefault("default", defaultFactory);
|
||||
|
||||
if (persistencePropertyDefault == LogPersistenceMode.Default)
|
||||
return defaultFactory();
|
||||
return persistencePropertyDefault;
|
||||
}
|
||||
|
||||
private static Dictionary<string, object?> StorePropertyUsingPersistenceMode(IDictionary<string, object?> inputs,
|
||||
IDictionary<string, object> persistenceModeConfiguration,
|
||||
LogPersistenceMode defaultLogPersistenceMode)
|
||||
{
|
||||
var result = new Dictionary<string, object?>();
|
||||
|
||||
foreach (var input in inputs)
|
||||
{
|
||||
var persistence = persistenceModeConfiguration.GetValueOrDefault(input.Key.Camelize(), () => defaultLogPersistenceMode);
|
||||
if (persistence.Equals(LogPersistenceMode.Include)
|
||||
|| (persistence.Equals(LogPersistenceMode.Default) && defaultLogPersistenceMode is LogPersistenceMode.Include or LogPersistenceMode.Default))
|
||||
result.Add(input.Key, input.Value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private ActivityStatus GetAggregateStatus(ActivityExecutionContext context)
|
||||
{
|
||||
// If any child activity is faulted, the aggregate status is faulted.
|
||||
|
|
|
|||
Loading…
Reference in a new issue