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:
edmand46
2026-09-04 14:03:41 +03:00
parent 05dd30f31d
commit 6c590ca520
52 changed files with 1304 additions and 2040 deletions
+97
View File
@@ -0,0 +1,97 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using RudderSdk.Core.Models.BattlePass;
namespace RudderSdk.Core;
/// <summary>
/// A scenario battle-pass node. Battle-pass operations are bound to this
/// node's scenario/node/run ids; <see cref="LevelUpAsync"/>, <see cref="EndAsync"/>
/// and a successful <see cref="PurchasePremiumAsync"/> post callbacks.
/// </summary>
public sealed class BattlePassEffect
{
private readonly EffectHandle _handle;
private readonly BattlePassService _battlePass;
internal BattlePassEffect(EffectHandle handle, BattlePassService battlePass)
{
_handle = handle;
_battlePass = battlePass;
}
/// <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>Reads a typed value from the node data.</summary>
public T Get<T>(string key, T defaultValue = default!) => _handle.Get(key, defaultValue);
/// <summary>Reads current progress (xp, level, premium ownership, claimed tiers) for this node.</summary>
public Task<GetBattlePassProgressResponse> GetProgressAsync(CancellationToken cancellationToken = default)
=> _battlePass.GetProgressAsync(_handle.ScenarioId, _handle.NodeId, cancellationToken);
/// <summary>Credits xp from a configured source.</summary>
public Task<AddBattlePassXpResponse> AddXpAsync(string source, long amount, CancellationToken cancellationToken = default)
=> _battlePass.AddXpAsync(new AddBattlePassXpRequest
{
ScenarioId = _handle.ScenarioId,
NodeId = _handle.NodeId,
RunId = _handle.RunId,
Source = source,
Amount = amount
}, cancellationToken);
/// <summary>
/// Claims a tier reward at a reached level.
/// <paramref name="track"/> is <see cref="BattlePassService.TrackFree"/> or <see cref="BattlePassService.TrackPremium"/>.
/// </summary>
public Task<ClaimBattlePassRewardResponse> ClaimRewardAsync(int level, string track, CancellationToken cancellationToken = default)
=> _battlePass.ClaimRewardAsync(new ClaimBattlePassRewardRequest
{
ScenarioId = _handle.ScenarioId,
NodeId = _handle.NodeId,
RunId = _handle.RunId,
Level = level,
Track = track
}, cancellationToken);
/// <summary>Purchases the premium track, then posts <c>onPremiumPurchase</c> on success.</summary>
public async Task<PurchaseBattlePassPremiumResponse> PurchasePremiumAsync(CancellationToken cancellationToken = default)
{
var response = await _battlePass.PurchasePremiumAsync(new PurchaseBattlePassPremiumRequest
{
ScenarioId = _handle.ScenarioId,
NodeId = _handle.NodeId,
RunId = _handle.RunId,
IdempotencyKey = Guid.NewGuid().ToString()
}, cancellationToken).ConfigureAwait(false);
if (response != null && response.Success == true)
await _handle.CompleteAsync("onPremiumPurchase", cancellationToken).ConfigureAwait(false);
return response!;
}
/// <summary>Posts the <c>onLevelUp</c> callback.</summary>
public Task LevelUpAsync(CancellationToken cancellationToken = default) => _handle.CompleteAsync("onLevelUp", cancellationToken);
/// <summary>Posts the <c>onLevelUp</c> callback (fire-and-forget).</summary>
public void LevelUp() => _handle.Complete("onLevelUp");
/// <summary>Posts the <c>onComplete</c> callback.</summary>
public Task EndAsync(CancellationToken cancellationToken = default) => _handle.CompleteAsync("onComplete", cancellationToken);
/// <summary>Posts the <c>onComplete</c> callback (fire-and-forget).</summary>
public void End() => _handle.Complete("onComplete");
}
+41
View File
@@ -0,0 +1,41 @@
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace RudderSdk.Core;
/// <summary>
/// A scenario battle-pass-level node — a single claimable tier.
/// <see cref="ClaimAsync"/> posts <c>onComplete</c>, which the server accepts
/// only once the player has reached the node's configured level.
/// </summary>
public sealed class BattlePassLevelEffect
{
private readonly EffectHandle _handle;
internal BattlePassLevelEffect(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>The tier level this node claims.</summary>
public int Level => _handle.Get("levelNumber", 0);
/// <summary>Node data payload.</summary>
public JObject Data => _handle.Data;
/// <summary>Reads a typed value from the node data.</summary>
public T Get<T>(string key, T defaultValue = default!) => _handle.Get(key, defaultValue);
/// <summary>Claims this tier; posts <c>onComplete</c>.</summary>
public Task ClaimAsync(CancellationToken cancellationToken = default) => _handle.CompleteAsync("onComplete", cancellationToken);
/// <summary>Claims this tier (fire-and-forget).</summary>
public void Claim() => _handle.Complete("onComplete");
}
+61
View File
@@ -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);
}
}
+40
View File
@@ -0,0 +1,40 @@
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace RudderSdk.Core;
/// <summary>A scenario notification node. <see cref="DoneAsync"/> posts the <c>output</c> callback.</summary>
public sealed class NotificationEffect
{
private readonly EffectHandle _handle;
internal NotificationEffect(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>Notification title.</summary>
public string Title => _handle.Get("title", string.Empty);
/// <summary>Notification message.</summary>
public string Message => _handle.Get("message", string.Empty);
/// <summary>Node data payload.</summary>
public JObject Data => _handle.Data;
/// <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>output</c> callback.</summary>
public Task DoneAsync(CancellationToken cancellationToken = default) => _handle.CompleteAsync("output", cancellationToken);
/// <summary>Posts the <c>output</c> callback (fire-and-forget).</summary>
public void Done() => _handle.Complete("output");
}
+62
View File
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace RudderSdk.Core;
/// <summary>
/// A scenario quest node. Report objective progress; the server auto-completes
/// the node once every objective is satisfied.
/// </summary>
public sealed class QuestEffect
{
private readonly EffectHandle _handle;
internal QuestEffect(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>Quest name from the node data.</summary>
public string Name => _handle.Get("name", string.Empty);
/// <summary>Objective definitions from the node data.</summary>
public IReadOnlyList<JObject> Objectives
{
get
{
if (_handle.Data["objectives"] is not JArray array)
return Array.Empty<JObject>();
var list = new List<JObject>(array.Count);
foreach (var item in array)
{
if (item is JObject obj)
list.Add(obj);
}
return list;
}
}
/// <summary>Node data payload.</summary>
public JObject Data => _handle.Data;
/// <summary>Reads a typed value from the node data.</summary>
public T Get<T>(string key, T defaultValue = default!) => _handle.Get(key, defaultValue);
/// <summary>Reports progress toward an objective via <c>POST /sdk/v1/scenarios/counter</c>.</summary>
public Task ReportProgressAsync(string objectiveId, long amount = 1, CancellationToken cancellationToken = default)
=> _handle.ReportProgressAsync(objectiveId, amount, cancellationToken);
/// <summary>Reports progress toward an objective (fire-and-forget).</summary>
public void ReportProgress(string objectiveId, long amount = 1) => _handle.ReportProgress(objectiveId, amount);
}
@@ -0,0 +1,17 @@
namespace RudderSdk.Core;
/// <summary>Payload of <see cref="EffectsService.OnScenarioCompleted"/>.</summary>
public sealed class ScenarioCompletedEffect
{
internal ScenarioCompletedEffect(string runId, string scenarioId)
{
RunId = runId;
ScenarioId = scenarioId;
}
/// <summary>Server-issued run id.</summary>
public string RunId { get; }
/// <summary>Scenario id.</summary>
public string ScenarioId { get; }
}
+27
View File
@@ -0,0 +1,27 @@
using System;
namespace RudderSdk.Core;
/// <summary>Payload of <see cref="EffectsService.OnScenarioFailed"/>.</summary>
public sealed class ScenarioFailedEffect
{
internal ScenarioFailedEffect(string runId, string scenarioId, string nodeId, Exception exception)
{
RunId = runId;
ScenarioId = scenarioId;
NodeId = nodeId;
Exception = exception;
}
/// <summary>Server-issued run id.</summary>
public string RunId { get; }
/// <summary>Scenario id.</summary>
public string ScenarioId { get; }
/// <summary>Node the failure happened at.</summary>
public string NodeId { get; }
/// <summary>The error that failed the run.</summary>
public Exception Exception { get; }
}
+74
View File
@@ -0,0 +1,74 @@
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace RudderSdk.Core;
/// <summary>A scenario store-offer node. Resolve it with <see cref="PurchaseAsync"/> or <see cref="DeclineAsync"/>.</summary>
public sealed class StoreOfferEffect
{
private readonly EffectHandle _handle;
internal StoreOfferEffect(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>Store slug from the node data, if present.</summary>
public string StoreSlug => _handle.Get("storeSlug", string.Empty);
/// <summary>Optional message from the node data.</summary>
public string? Message
{
get
{
var value = _handle.Get<string?>("message", null);
return string.IsNullOrEmpty(value) ? null : value;
}
}
/// <summary>Node data payload.</summary>
public JObject Data => _handle.Data;
/// <summary>True after the offer 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>onPurchase</c> callback.</summary>
public Task PurchaseAsync(CancellationToken cancellationToken = default) => ResolveAsync("onPurchase", cancellationToken);
/// <summary>Posts the <c>onPurchase</c> callback (fire-and-forget).</summary>
public void Purchase() => Resolve("onPurchase");
/// <summary>Posts the <c>onDecline</c> callback.</summary>
public Task DeclineAsync(CancellationToken cancellationToken = default) => ResolveAsync("onDecline", cancellationToken);
/// <summary>Posts the <c>onDecline</c> callback (fire-and-forget).</summary>
public void Decline() => Resolve("onDecline");
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);
}
}
+34
View File
@@ -0,0 +1,34 @@
using System;
using Newtonsoft.Json.Linq;
namespace RudderSdk.Core;
/// <summary>A scenario wait node. The run resumes when the server advances it at <see cref="DeadlineUtc"/>.</summary>
public sealed class WaitEffect
{
private readonly EffectHandle _handle;
internal WaitEffect(EffectHandle handle, DateTimeOffset deadlineUtc)
{
_handle = handle;
DeadlineUtc = deadlineUtc;
}
/// <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>When the wait ends (UTC).</summary>
public DateTimeOffset DeadlineUtc { get; }
/// <summary>Node data payload.</summary>
public JObject Data => _handle.Data;
/// <summary>Reads a typed value from the node data.</summary>
public T Get<T>(string key, T defaultValue = default!) => _handle.Get(key, defaultValue);
}