41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
|
|
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");
|
||
|
|
}
|