2017-01-31 11:01:08 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.Flow
|
|
|
|
|
{
|
2019-08-15 09:26:55 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides persistency for flow states.
|
|
|
|
|
/// </summary>
|
2017-08-14 11:58:01 +00:00
|
|
|
|
public interface IFlowRepository
|
2017-01-31 11:01:08 +00:00
|
|
|
|
{
|
2019-08-15 09:26:55 +00: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>
|
2021-11-02 14:48:14 +00:00
|
|
|
|
Task<IEnumerable<FlowRecord<T>>> GetStates<T>();
|
2019-08-15 09:26:55 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stores a new flow state. Guaranteed to be run in a lock for the specified flow ID.
|
|
|
|
|
/// </summary>
|
2021-11-02 14:48:14 +00: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 09:26:55 +00:00
|
|
|
|
/// <returns></returns>
|
2017-08-14 11:58:01 +00:00
|
|
|
|
Task CreateState<T>(Guid flowID, T state, DateTime timestamp);
|
2019-08-15 09:26:55 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates an existing flow state. Guaranteed to be run in a lock for the specified flow ID.
|
|
|
|
|
/// </summary>
|
2021-11-02 14:48:14 +00:00
|
|
|
|
/// <param name="flowID">The unique ID of the flow.</param>
|
|
|
|
|
/// <param name="state">The flow state to be stored.</param>
|
2017-08-14 11:58:01 +00:00
|
|
|
|
Task UpdateState<T>(Guid flowID, T state);
|
2019-08-15 09:26:55 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delete a flow state. Guaranteed to be run in a lock for the specified flow ID.
|
|
|
|
|
/// </summary>
|
2021-11-02 14:48:14 +00:00
|
|
|
|
/// <param name="flowID">The unique ID of the flow.</param>
|
2017-01-31 11:01:08 +00:00
|
|
|
|
Task DeleteState(Guid flowID);
|
|
|
|
|
}
|
2021-11-02 14:48:14 +00: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 11:01:08 +00:00
|
|
|
|
}
|