Add EventName property to ActivityExecutionLogRecord (replacing Message property)

This commit is contained in:
Sipke Schoorstra 2021-04-20 10:31:35 +02:00
parent dca9bf2509
commit 33250c9bbd
17 changed files with 51 additions and 29 deletions

View file

@ -12,23 +12,23 @@ namespace Elsa
{
public static class WorkflowExecutionLogExtensions
{
public static async Task AddEntryAsync(this IWorkflowExecutionLog log, string message, WorkflowInstance workflowInstance, IActivityBlueprint activity, CancellationToken cancellationToken = default) =>
await log.AddEntryAsync(message, workflowInstance, activity, default, default, cancellationToken);
public static async Task AddEntryAsync(this IWorkflowExecutionLog log, string message, ActivityExecutionContext activityExecutionContext, JObject? data, CancellationToken cancellationToken = default, [CallerLineNumber]int line = default, [CallerFilePath] string? sourceFile = default) =>
await log.AddEntryAsync(message, activityExecutionContext.WorkflowInstance, activityExecutionContext.ActivityBlueprint, data, $"{Path.GetFileName(sourceFile)}:{line}", cancellationToken);
public static async Task AddEntryAsync(this IWorkflowExecutionLog log, string message, ActivityExecutionContext activityExecutionContext, CancellationToken cancellationToken = default, [CallerLineNumber]int line = default, [CallerFilePath] string? sourceFile = default) =>
await log.AddEntryAsync(message, activityExecutionContext, default, cancellationToken, line, sourceFile);
public static async Task AddEntryAsync(this IWorkflowExecutionLog log, string eventName, WorkflowInstance workflowInstance, IActivityBlueprint activity, string? message, CancellationToken cancellationToken = default, [CallerLineNumber] int line = default, [CallerFilePath] string? sourceFile = default) =>
await log.AddEntryAsync(eventName, workflowInstance, activity, message, default, $"{Path.GetFileName(sourceFile)}:{line}", cancellationToken);
public static async Task AddEntryAsync(this IWorkflowExecutionLog log, string message, WorkflowInstance workflowInstance, IActivityBlueprint activity, JObject? data, string? source, CancellationToken cancellationToken = default)
public static async Task AddEntryAsync(this IWorkflowExecutionLog log, string eventName, ActivityExecutionContext activityExecutionContext, string? message, JObject? data, CancellationToken cancellationToken = default, [CallerLineNumber] int line = default, [CallerFilePath] string? sourceFile = default) =>
await log.AddEntryAsync(eventName, activityExecutionContext.WorkflowInstance, activityExecutionContext.ActivityBlueprint, message, data, $"{Path.GetFileName(sourceFile)}:{line}", cancellationToken);
public static async Task AddEntryAsync(this IWorkflowExecutionLog log, string eventName, ActivityExecutionContext activityExecutionContext, string? message, CancellationToken cancellationToken = default, [CallerLineNumber] int line = default, [CallerFilePath] string? sourceFile = default) =>
await log.AddEntryAsync(eventName, activityExecutionContext, message, default, cancellationToken, line, sourceFile);
public static async Task AddEntryAsync(this IWorkflowExecutionLog log, string eventName, WorkflowInstance workflowInstance, IActivityBlueprint activity, string? message, JObject? data, string? source, CancellationToken cancellationToken = default)
{
var tenantId = workflowInstance.TenantId;
var workflowInstanceId = workflowInstance.Id;
var activityId = activity.Id;
var activityType = activity.Type;
source ??= activity.Source;
await log.AddEntryAsync(message, workflowInstanceId, activityId, activityType, tenantId, source, data, cancellationToken);
await log.AddEntryAsync(workflowInstanceId, activityId, activityType, eventName, message, tenantId, source, data, cancellationToken);
}
}
}

View file

@ -9,7 +9,7 @@ namespace Elsa.Models
{
}
public WorkflowExecutionLogRecord(string id, string? tenantId, string workflowInstanceId, string activityId, string activityType, Instant timestamp, string? message, string? source = default, JObject? data = default)
public WorkflowExecutionLogRecord(string id, string? tenantId, string workflowInstanceId, string activityId, string activityType, Instant timestamp, string eventName, string? message, string? source = default, JObject? data = default)
{
Id = id;
TenantId = tenantId;
@ -17,6 +17,7 @@ namespace Elsa.Models
ActivityId = activityId;
ActivityType = activityType;
Timestamp = timestamp;
EventName = eventName;
Message = message;
Source = source;
Data = data;
@ -27,6 +28,7 @@ namespace Elsa.Models
public string ActivityId { get; set; } = default!;
public string ActivityType { get; set; } = default!;
public Instant Timestamp { get; set; } = default!;
public string? EventName { get; set; }
public string? Message { get; set; }
public string? Source { get; set; }
public JObject? Data { get; set; }

View file

@ -6,6 +6,6 @@ namespace Elsa.Services
{
public interface IWorkflowExecutionLog
{
Task AddEntryAsync(string message, string workflowInstanceId, string activityId, string activityType, string? tenantId, string? source, JObject? data, CancellationToken cancellationToken);
Task AddEntryAsync(string workflowInstanceId, string activityId, string activityType, string eventName, string? message, string? tenantId, string? source, JObject? data, CancellationToken cancellationToken = default);
}
}

View file

@ -10,14 +10,9 @@ namespace Elsa.Handlers
public class WriteWorkflowExecutionLog : INotificationHandler<ActivityExecuting>, INotificationHandler<ActivityExecuted>, INotificationHandler<ActivityFaulted>
{
private readonly IWorkflowExecutionLog _workflowExecutionLog;
public WriteWorkflowExecutionLog(IWorkflowExecutionLog workflowExecutionLog)
{
_workflowExecutionLog = workflowExecutionLog;
}
public async Task Handle(ActivityExecuting notification, CancellationToken cancellationToken) => await WriteEntryAsync(notification.Resuming ? "Resuming" : "Executing", notification, null, cancellationToken);
public async Task Handle(ActivityExecuted notification, CancellationToken cancellationToken) => await WriteEntryAsync(notification.Resuming ? "Resumed" : "Executed", notification, null, cancellationToken);
public WriteWorkflowExecutionLog(IWorkflowExecutionLog workflowExecutionLog) => _workflowExecutionLog = workflowExecutionLog;
public async Task Handle(ActivityExecuting notification, CancellationToken cancellationToken) => await WriteEntryAsync(notification.Resuming ? "Resuming" : "Executing", default, notification, null, cancellationToken);
public async Task Handle(ActivityExecuted notification, CancellationToken cancellationToken) => await WriteEntryAsync(notification.Resuming ? "Resumed" : "Executed", default, notification, null, cancellationToken);
public async Task Handle(ActivityFaulted notification, CancellationToken cancellationToken)
{
@ -28,15 +23,15 @@ namespace Elsa.Handlers
exception.Message,
exception.StackTrace
});
await WriteEntryAsync("Faulted", notification, data, cancellationToken);
await WriteEntryAsync("Faulted", exception.Message, notification, data, cancellationToken);
}
private async Task WriteEntryAsync(string message, ActivityNotification notification, JObject? data, CancellationToken cancellationToken)
private async Task WriteEntryAsync(string eventName, string? message, ActivityNotification notification, JObject? data, CancellationToken cancellationToken)
{
var workflowInstance = notification.WorkflowExecutionContext.WorkflowInstance;
var activityBlueprint = notification.Activity;
await _workflowExecutionLog.AddEntryAsync(message, workflowInstance, activityBlueprint, data, default, cancellationToken);
await _workflowExecutionLog.AddEntryAsync(eventName, workflowInstance, activityBlueprint, message, data, default, cancellationToken);
}
}
}

View file

@ -20,11 +20,11 @@ namespace Elsa.Services
_clock = clock;
}
public async Task AddEntryAsync(string message, string workflowInstanceId, string activityId, string activityType, string? tenantId, string? source, JObject? data, CancellationToken cancellationToken)
public async Task AddEntryAsync(string workflowInstanceId, string activityId, string activityType, string eventName, string? message, string? tenantId, string? source, JObject? data, CancellationToken cancellationToken = default)
{
var id = _idGenerator.Generate();
var timeStamp = _clock.GetCurrentInstant();
var record = new WorkflowExecutionLogRecord(id, tenantId, workflowInstanceId, activityId, activityType, timeStamp, message, source, data);
var record = new WorkflowExecutionLogRecord(id, tenantId, workflowInstanceId, activityId, activityType, timeStamp, eventName, message, source, data);
await _store.SaveAsync(record, cancellationToken);
}
}

View file

@ -10,7 +10,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Elsa.Persistence.EntityFramework.PostgreSql.Migrations
{
[DbContext(typeof(ElsaContext))]
[Migration("20210416134539_Initial")]
[Migration("20210420081700_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -157,6 +157,9 @@ namespace Elsa.Persistence.EntityFramework.PostgreSql.Migrations
b.Property<string>("Data")
.HasColumnType("text");
b.Property<string>("EventName")
.HasColumnType("text");
b.Property<string>("Message")
.HasColumnType("text");

View file

@ -58,6 +58,7 @@ namespace Elsa.Persistence.EntityFramework.PostgreSql.Migrations
ActivityId = table.Column<string>(type: "text", nullable: false),
ActivityType = table.Column<string>(type: "text", nullable: false),
Timestamp = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
EventName = table.Column<string>(type: "text", nullable: true),
Message = table.Column<string>(type: "text", nullable: true),
Source = table.Column<string>(type: "text", nullable: true),
Data = table.Column<string>(type: "text", nullable: true)

View file

@ -155,6 +155,9 @@ namespace Elsa.Persistence.EntityFramework.PostgreSql.Migrations
b.Property<string>("Data")
.HasColumnType("text");
b.Property<string>("EventName")
.HasColumnType("text");
b.Property<string>("Message")
.HasColumnType("text");

View file

@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Elsa.Persistence.EntityFramework.SqlServer.Migrations
{
[DbContext(typeof(ElsaContext))]
[Migration("20210416134632_Initial")]
[Migration("20210420081809_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -157,6 +157,9 @@ namespace Elsa.Persistence.EntityFramework.SqlServer.Migrations
b.Property<string>("Data")
.HasColumnType("nvarchar(max)");
b.Property<string>("EventName")
.HasColumnType("nvarchar(max)");
b.Property<string>("Message")
.HasColumnType("nvarchar(max)");

View file

@ -58,6 +58,7 @@ namespace Elsa.Persistence.EntityFramework.SqlServer.Migrations
ActivityId = table.Column<string>(type: "nvarchar(450)", nullable: false),
ActivityType = table.Column<string>(type: "nvarchar(450)", nullable: false),
Timestamp = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
EventName = table.Column<string>(type: "nvarchar(max)", nullable: true),
Message = table.Column<string>(type: "nvarchar(max)", nullable: true),
Source = table.Column<string>(type: "nvarchar(max)", nullable: true),
Data = table.Column<string>(type: "nvarchar(max)", nullable: true)

View file

@ -155,6 +155,9 @@ namespace Elsa.Persistence.EntityFramework.SqlServer.Migrations
b.Property<string>("Data")
.HasColumnType("nvarchar(max)");
b.Property<string>("EventName")
.HasColumnType("nvarchar(max)");
b.Property<string>("Message")
.HasColumnType("nvarchar(max)");

View file

@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Elsa.Persistence.EntityFramework.Sqlite.Migrations
{
[DbContext(typeof(ElsaContext))]
[Migration("20210416134603_Initial")]
[Migration("20210420081738_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -154,6 +154,9 @@ namespace Elsa.Persistence.EntityFramework.Sqlite.Migrations
b.Property<string>("Data")
.HasColumnType("TEXT");
b.Property<string>("EventName")
.HasColumnType("TEXT");
b.Property<string>("Message")
.HasColumnType("TEXT");

View file

@ -58,6 +58,7 @@ namespace Elsa.Persistence.EntityFramework.Sqlite.Migrations
ActivityId = table.Column<string>(type: "TEXT", nullable: false),
ActivityType = table.Column<string>(type: "TEXT", nullable: false),
Timestamp = table.Column<DateTime>(type: "TEXT", nullable: false),
EventName = table.Column<string>(type: "TEXT", nullable: true),
Message = table.Column<string>(type: "TEXT", nullable: true),
Source = table.Column<string>(type: "TEXT", nullable: true),
Data = table.Column<string>(type: "TEXT", nullable: true)

View file

@ -152,6 +152,9 @@ namespace Elsa.Persistence.EntityFramework.Sqlite.Migrations
b.Property<string>("Data")
.HasColumnType("TEXT");
b.Property<string>("EventName")
.HasColumnType("TEXT");
b.Property<string>("Message")
.HasColumnType("TEXT");

View file

@ -11,6 +11,7 @@ namespace Elsa.Persistence.YesSql.Documents
public string ActivityId { get; set; } = default!;
public string ActivityType { get; set; } = default!;
public Instant Timestamp { get; set; }
public string EventName { get; set; } = default!;
public string? Message { get; set; }
public string? Source { get; set; }
public JObject? Data { get; set; }

View file

@ -10,6 +10,7 @@ namespace Elsa.Persistence.YesSql.Indexes
public string? TenantId { get; set; }
public string RecordId { get; set; } = default!;
public string WorkflowInstanceId { get; set; } = default!;
public string EventName { get; set; } = default!;
public DateTime Timestamp { get; set; }
}
@ -26,6 +27,7 @@ namespace Elsa.Persistence.YesSql.Indexes
RecordId = record.RecordId,
TenantId = record.TenantId,
WorkflowInstanceId = record.WorkflowInstanceId,
EventName = record.EventName,
Timestamp = record.Timestamp.ToDateTimeUtc()
}
);

View file

@ -54,6 +54,7 @@ namespace Elsa.Persistence.YesSql
.Column<string?>(nameof(WorkflowExecutionLogRecordIndex.RecordId))
.Column<string?>(nameof(WorkflowExecutionLogRecordIndex.TenantId))
.Column<string>(nameof(WorkflowExecutionLogRecordIndex.WorkflowInstanceId))
.Column<string>(nameof(WorkflowExecutionLogRecordIndex.EventName))
.Column<DateTime>(nameof(WorkflowExecutionLogRecordIndex.Timestamp)),
CollectionNames.WorkflowExecutionLog);