Store workflow state created timestamp
This commit is contained in:
parent
026430fd2d
commit
92ffeed4ea
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue