Server-side scenario execution: effects client replaces local engine
- client.Effects: typed effects + completion methods posting scenario callbacks - client.Scenario reduced to TriggerAsync - pending polling via Update() pump: 30s heartbeat + wait-deadline checks - local engine, plan persistence (IPlanStateStore) and resume removed - RealtimeService and realtime transports removed (relay never deployed) - dead IPlanScheduler leftover removed - models regenerated from openapi (ExecutionPlan/BoundaryNode gone, PendingEffect added)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace RudderSdk.Core;
|
||||
|
||||
/// <summary>A scenario leaderboard node. End it with <see cref="EndAsync"/> or claim with <see cref="ClaimAsync"/>.</summary>
|
||||
public sealed class LeaderboardEffect
|
||||
{
|
||||
private readonly EffectHandle _handle;
|
||||
|
||||
internal LeaderboardEffect(EffectHandle handle) => _handle = handle;
|
||||
|
||||
/// <summary>Run id.</summary>
|
||||
public string RunId => _handle.RunId;
|
||||
|
||||
/// <summary>Scenario id.</summary>
|
||||
public string ScenarioId => _handle.ScenarioId;
|
||||
|
||||
/// <summary>Node id.</summary>
|
||||
public string NodeId => _handle.NodeId;
|
||||
|
||||
/// <summary>Node data payload.</summary>
|
||||
public JObject Data => _handle.Data;
|
||||
|
||||
/// <summary>True after the effect was resolved once.</summary>
|
||||
public bool IsResolved { get; private set; }
|
||||
|
||||
/// <summary>Reads a typed value from the node data.</summary>
|
||||
public T Get<T>(string key, T defaultValue = default!) => _handle.Get(key, defaultValue);
|
||||
|
||||
/// <summary>Posts the <c>onEnd</c> callback.</summary>
|
||||
public Task EndAsync(CancellationToken cancellationToken = default) => ResolveAsync("onEnd", cancellationToken);
|
||||
|
||||
/// <summary>Posts the <c>onEnd</c> callback (fire-and-forget).</summary>
|
||||
public void End() => Resolve("onEnd");
|
||||
|
||||
/// <summary>Posts the <c>onClaim</c> callback. The server matches live rank to a place.</summary>
|
||||
public Task ClaimAsync(CancellationToken cancellationToken = default) => ResolveAsync("onClaim", cancellationToken);
|
||||
|
||||
/// <summary>Posts the <c>onClaim</c> callback (fire-and-forget).</summary>
|
||||
public void Claim() => Resolve("onClaim");
|
||||
|
||||
private async Task ResolveAsync(string handle, CancellationToken cancellationToken)
|
||||
{
|
||||
if (IsResolved)
|
||||
return;
|
||||
|
||||
IsResolved = true;
|
||||
await _handle.CompleteAsync(handle, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private void Resolve(string handle)
|
||||
{
|
||||
if (IsResolved)
|
||||
return;
|
||||
|
||||
IsResolved = true;
|
||||
_handle.Complete(handle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user