Skip to content

Commit 77f839d

Browse files
authored
Added FirstExecutionRunId to WorkflowInfo (#516)
1 parent deb2756 commit 77f839d

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

src/Temporalio/Worker/WorkflowInstance.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public WorkflowInstance(WorkflowInstanceDetails details)
183183
ContinuedRunId: NonEmptyOrNull(start.ContinuedFromExecutionRunId),
184184
CronSchedule: NonEmptyOrNull(start.CronSchedule),
185185
ExecutionTimeout: start.WorkflowExecutionTimeout?.ToTimeSpan(),
186+
FirstExecutionRunId: start.FirstExecutionRunId,
186187
Headers: start.Headers,
187188
LastFailure: lastFailure,
188189
LastResult: lastResult,

src/Temporalio/Workflows/WorkflowInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Temporalio.Workflows
1212
/// <param name="ContinuedRunId">Run ID if this was continued.</param>
1313
/// <param name="CronSchedule">Cron schedule if applicable.</param>
1414
/// <param name="ExecutionTimeout">Execution timeout for the workflow.</param>
15+
/// <param name="FirstExecutionRunId">The very first run ID the workflow ever had, following continuation chains.</param>
1516
/// <param name="Headers">Headers from when the workflow was started.</param>
1617
/// <param name="LastFailure">Failure if this workflow run is a continuation of a failure.</param>
1718
/// <param name="LastResult">Successful result if this workflow is a continuation of a success.</param>
@@ -38,6 +39,7 @@ public record WorkflowInfo(
3839
string? ContinuedRunId,
3940
string? CronSchedule,
4041
TimeSpan? ExecutionTimeout,
42+
string FirstExecutionRunId,
4143
IReadOnlyDictionary<string, Api.Common.V1.Payload>? Headers,
4244
Exception? LastFailure,
4345
IReadOnlyCollection<IRawValue>? LastResult,
@@ -64,6 +66,7 @@ public record WorkflowInfo(
6466
{
6567
["Attempt"] = Attempt,
6668
["Namespace"] = Namespace,
69+
["FirstExecutionRunId"] = FirstExecutionRunId,
6770
["RunId"] = RunId,
6871
["TaskQueue"] = TaskQueue,
6972
["WorkflowId"] = WorkflowId,

tests/Temporalio.Tests/Client/WorkflowHandleTests.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,24 @@ public async Task GetResultAsync_ContinueAsNew_ProperlyFollowed()
1818
{
1919
// Start with a single round of continue as new
2020
var arg = new KSWorkflowParams(
21-
new KSAction(ContinueAsNew: new(WhileAboveZero: 1, Result: "Some String")));
21+
new KSAction(ContinueAsNew: new(WhileAboveZero: 1)));
2222
var handle = await Client.StartWorkflowAsync(
2323
(IKitchenSinkWorkflow wf) => wf.RunAsync(arg),
2424
new(id: $"workflow-{Guid.NewGuid()}", taskQueue: Env.KitchenSinkWorkerTaskQueue));
2525

2626
// Check result with and without following
27-
Assert.Equal("Some String", await handle.GetResultAsync());
28-
await Assert.ThrowsAsync<Exceptions.WorkflowContinuedAsNewException>(
29-
async () => await handle.GetResultAsync(followRuns: false));
27+
Assert.Equal(handle.ResultRunId, await handle.GetResultAsync());
28+
try
29+
{
30+
await handle.GetResultAsync(followRuns: false);
31+
Assert.Fail("Should have thrown an exception");
32+
}
33+
catch (Exceptions.WorkflowContinuedAsNewException ex)
34+
{
35+
Assert.NotEqual(handle.ResultRunId, ex.NewRunId);
36+
var continuedHandle = Client.GetWorkflowHandle<IKitchenSinkWorkflow, string>(handle.Id, runId: ex.NewRunId);
37+
Assert.Equal(handle.ResultRunId, await continuedHandle.GetResultAsync(followRuns: false));
38+
}
3039
}
3140

3241
[Fact]

tests/Temporalio.Tests/IKitchenSinkWorkflow.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public record KSErrorAction(
7070
[property: JsonPropertyName("is_benign")] bool IsBenign = false);
7171

7272
public record KSContinueAsNewAction(
73-
[property: JsonPropertyName("while_above_zero")] int? WhileAboveZero = null,
74-
[property: JsonPropertyName("result")] object? Result = null);
73+
[property: JsonPropertyName("while_above_zero")] int? WhileAboveZero = null);
7574

7675
public record KSSleepAction(
7776
[property: JsonPropertyName("millis")] long Millis);

tests/Temporalio.Tests/KitchenSinkWorkflow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ action with
104104
throw Workflow.CreateContinueAsNewException(
105105
(IKitchenSinkWorkflow wf) => wf.RunAsync(args));
106106
}
107-
return (true, action.ContinueAsNew.Result);
107+
return (true, Workflow.Info.FirstExecutionRunId);
108108
}
109109
else if (action.Sleep != null)
110110
{

0 commit comments

Comments
 (0)