using Newtonsoft.Json.Linq;
using Unity.Pipeline.Commands;
namespace Unity.Pipeline
{
///
/// Everything known about one finished /api/exec interaction, handed to
/// .
///
/// The transaction half and the execution half are independent, because the two are not the
/// same set: a request can produce a transaction without executing anything (rejected for
/// size, malformed JSON, unknown command, busy host, job queue full), and a detached job
/// executes long after its own response was sent, producing no transaction at all. Consumers
/// read the half they care about and skip the ones that lack it.
///
public readonly struct CommandExecutionInfo
{
///
/// Raw request JSON, or null when there is no transaction to report — a detached job
/// completing after its submission response was already sent.
///
public string RequestJson { get; }
///
/// Raw response JSON as it went on the wire, or null alongside a null
/// .
///
public string ResponseJson { get; }
///
/// The command that ran, or null when the request was rejected before any command
/// executed.
///
public CommandInfo Command { get; }
///
/// The parameters the command was invoked with, or null when no command ran. Lets a consumer
/// answer questions about WHAT was asked, not just which command served it — the analytics
/// reporter reads an eval body from here to decide whether a concrete command already covers
/// it. Never serialized anywhere: it is in-memory only, for the moment between the command
/// finishing and the post-command work running.
///
public JObject Parameters { get; }
///
/// Whether the command reported success. False when it threw AND when it returned a
/// response carrying its own failure (eval, code reload and test runs all do the latter).
/// Meaningless when is null.
///
public bool Success { get; }
///
/// Wall-clock milliseconds spent inside the command itself, excluding the wait for the
/// one-command-at-a-time execution gate. Zero when is null.
///
public long DurationMs { get; }
/// Create an info describing one finished interaction.
/// Raw request JSON, or null when there is no transaction.
/// Raw response JSON, or null alongside a null request.
/// The command that ran, or null when none did.
/// Whether the command reported success.
/// Milliseconds spent inside the command.
/// The parameters the command was invoked with, or null.
public CommandExecutionInfo(string requestJson, string responseJson, CommandInfo command,
bool success, long durationMs, JObject parameters = null)
{
RequestJson = requestJson;
ResponseJson = responseJson;
Command = command;
Success = success;
DurationMs = durationMs;
Parameters = parameters;
}
///
/// A detached job that just finished: an execution with no transaction, since the client
/// already received its job handle.
///
/// The command the job ran.
/// Whether the command reported success.
/// Milliseconds spent inside the command.
/// The parameters the job ran the command with.
/// An info carrying the execution and no transaction.
public static CommandExecutionInfo ForDetachedJob(CommandInfo command, bool success, long durationMs,
JObject parameters = null)
{
return new CommandExecutionInfo(null, null, command, success, durationMs, parameters);
}
}
}