2017-01-31 12:01:08 +01:00
|
|
|
|
using System;
|
2021-11-02 15:48:14 +01:00
|
|
|
|
using System.Collections.Generic;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2017-02-05 23:22:34 +01:00
|
|
|
|
using Tapeti.Flow.Default;
|
2017-01-31 12:01:08 +01:00
|
|
|
|
|
2018-12-19 20:50:56 +01:00
|
|
|
|
// ReSharper disable UnusedMember.Global
|
|
|
|
|
|
2017-01-31 12:01:08 +01:00
|
|
|
|
namespace Tapeti.Flow
|
|
|
|
|
{
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides a way to store and load flow state.
|
|
|
|
|
/// </summary>
|
2017-01-31 12:01:08 +01:00
|
|
|
|
public interface IFlowStore
|
|
|
|
|
{
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Must be called during application startup before subscribing or starting a flow.
|
|
|
|
|
/// If using an IFlowRepository that requires an update (such as creating tables) make
|
|
|
|
|
/// sure it is called before calling Load.
|
|
|
|
|
/// </summary>
|
2022-02-09 11:26:56 +01:00
|
|
|
|
ValueTask Load();
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Looks up the FlowID corresponding to a ContinuationID. For internal use.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="continuationID"></param>
|
2022-02-09 11:26:56 +01:00
|
|
|
|
ValueTask<Guid?> FindFlowID(Guid continuationID);
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Acquires a lock on the flow with the specified FlowID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="flowID"></param>
|
2022-02-09 11:26:56 +01:00
|
|
|
|
ValueTask<IFlowStateLock> LockFlowState(Guid flowID);
|
2021-11-02 15:48:14 +01:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns information about the currently active flows.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// This is intended for monitoring purposes and should be treated as a snapshot.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
/// <param name="minimumAge">The minimum age of the flow before it is included in the result. Set to TimeSpan.Zero to return all active flows.</param>
|
2022-02-09 11:26:56 +01:00
|
|
|
|
ValueTask<IEnumerable<ActiveFlow>> GetActiveFlows(TimeSpan minimumAge);
|
2017-01-31 12:01:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a lock on the flow state, to provide thread safety.
|
|
|
|
|
/// </summary>
|
2017-01-31 12:01:08 +01:00
|
|
|
|
public interface IFlowStateLock : IDisposable
|
|
|
|
|
{
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The unique ID of the flow state.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
Guid FlowID { get; }
|
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Acquires a copy of the flow state.
|
|
|
|
|
/// </summary>
|
2022-11-23 09:13:38 +01:00
|
|
|
|
ValueTask<FlowState?> GetFlowState();
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Stores the new flow state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="flowState"></param>
|
2019-08-19 09:33:07 +02:00
|
|
|
|
/// <param name="persistent"></param>
|
2022-02-09 11:26:56 +01:00
|
|
|
|
ValueTask StoreFlowState(FlowState flowState, bool persistent);
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Disposes of the flow state corresponding to this Flow ID.
|
|
|
|
|
/// </summary>
|
2022-02-09 11:26:56 +01:00
|
|
|
|
ValueTask DeleteFlowState();
|
2017-01-31 12:01:08 +01:00
|
|
|
|
}
|
2021-11-02 15:48:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains information about an active flow, as returned by <see cref="IFlowStore.GetActiveFlows"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ActiveFlow
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The ID of the active flow.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Guid FlowID { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The time when the flow was initially created.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public DateTime CreationTime { get; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create a new instance of an ActiveFlow.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="flowID">The ID of the active flow.</param>
|
|
|
|
|
/// <param name="creationTime">The time when the flow was initially created.</param>
|
|
|
|
|
public ActiveFlow(Guid flowID, DateTime creationTime)
|
|
|
|
|
{
|
|
|
|
|
FlowID = flowID;
|
|
|
|
|
CreationTime = creationTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-31 12:01:08 +01:00
|
|
|
|
}
|