2017-01-31 12:01:08 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.Flow
|
|
|
|
|
{
|
2019-08-15 11:26:55 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides persistency for flow states.
|
|
|
|
|
/// </summary>
|
2017-08-14 13:58:01 +02:00
|
|
|
|
public interface IFlowRepository
|
2017-01-31 12:01:08 +01:00
|
|
|
|
{
|
2019-08-15 11:26:55 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Load the previously persisted flow states.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>A list of flow states, where the key is the unique Flow ID and the value is the deserialized T.</returns>
|
2022-02-09 11:26:56 +01:00
|
|
|
|
ValueTask<IEnumerable<FlowRecord<T>>> GetStates<T>();
|
2019-08-15 11:26:55 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stores a new flow state. Guaranteed to be run in a lock for the specified flow ID.
|
|
|
|
|
/// </summary>
|
2021-11-02 15:48:14 +01:00
|
|
|
|
/// <param name="flowID">The unique ID of the flow.</param>
|
|
|
|
|
/// <param name="state">The flow state to be stored.</param>
|
|
|
|
|
/// <param name="timestamp">The time when the flow was initially created.</param>
|
2019-08-15 11:26:55 +02:00
|
|
|
|
/// <returns></returns>
|
2022-02-09 11:26:56 +01:00
|
|
|
|
ValueTask CreateState<T>(Guid flowID, T state, DateTime timestamp);
|
2019-08-15 11:26:55 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates an existing flow state. Guaranteed to be run in a lock for the specified flow ID.
|
|
|
|
|
/// </summary>
|
2021-11-02 15:48:14 +01:00
|
|
|
|
/// <param name="flowID">The unique ID of the flow.</param>
|
|
|
|
|
/// <param name="state">The flow state to be stored.</param>
|
2022-02-09 11:26:56 +01:00
|
|
|
|
ValueTask UpdateState<T>(Guid flowID, T state);
|
2019-08-15 11:26:55 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete a flow state. Guaranteed to be run in a lock for the specified flow ID.
|
|
|
|
|
/// </summary>
|
2021-11-02 15:48:14 +01:00
|
|
|
|
/// <param name="flowID">The unique ID of the flow.</param>
|
2022-02-09 11:26:56 +01:00
|
|
|
|
ValueTask DeleteState(Guid flowID);
|
2017-01-31 12:01:08 +01:00
|
|
|
|
}
|
2021-11-02 15:48:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains information about a persisted flow state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class FlowRecord<T>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The unique ID of the flow.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Guid FlowID { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The time when the flow was initially created.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DateTime CreationTime { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The stored flow state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public T FlowState { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new instance of a FlowRecord.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="flowID"></param>
|
|
|
|
|
/// <param name="creationTime"></param>
|
|
|
|
|
/// <param name="flowState"></param>
|
|
|
|
|
public FlowRecord(Guid flowID, DateTime creationTime, T flowState)
|
|
|
|
|
{
|
|
|
|
|
FlowID = flowID;
|
|
|
|
|
CreationTime = creationTime;
|
|
|
|
|
FlowState = flowState;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-31 12:01:08 +01:00
|
|
|
|
}
|