Store workflow state created timestamp

This commit is contained in:
Sipke Schoorstra 2022-12-07 20:58:17 +01:00
parent 026430fd2d
commit 92ffeed4ea

View file

@ -18,9 +18,9 @@ public class EFCoreWorkflowStateStore : IWorkflowStateStore
private readonly IDbContextFactory<RuntimeElsaDbContext> _dbContextFactory;
public EFCoreWorkflowStateStore(
IDbContextFactory<RuntimeElsaDbContext> dbContextFactory,
Store<RuntimeElsaDbContext, WorkflowState> store,
SerializerOptionsProvider serializerOptionsProvider,
IDbContextFactory<RuntimeElsaDbContext> dbContextFactory,
Store<RuntimeElsaDbContext, WorkflowState> store,
SerializerOptionsProvider serializerOptionsProvider,
ISystemClock systemClock)
{
_serializerOptionsProvider = serializerOptionsProvider;
@ -35,9 +35,8 @@ public class EFCoreWorkflowStateStore : IWorkflowStateStore
var json = JsonSerializer.Serialize(state, options);
var now = _systemClock.UtcNow;
var entry = dbContext.Entry(state);
var record = await dbContext.WorkflowStates.FirstOrDefaultAsync(x => x.Id == state.Id, cancellationToken);
if (record == null)
if (entry.Property<DateTimeOffset>("CreatedAt").CurrentValue == DateTimeOffset.MinValue)
entry.Property<DateTimeOffset>("CreatedAt").CurrentValue = now;
entry.Property<string>("Data").CurrentValue = json;
@ -55,10 +54,10 @@ public class EFCoreWorkflowStateStore : IWorkflowStateStore
if (entity == null)
return null;
var entry = dbContext.Entry(entity);
var json = entry.Property<string>("Data").CurrentValue;
// For reading string:object dictionaries where the objects would otherwise be read as JsonElement values.
options.Converters.Add(new SystemObjectPrimitiveConverter());
return JsonSerializer.Deserialize<WorkflowState>(json, options);