Skip to content

Commit b94084b

Browse files
authored
Add WorkflowInfo.WorkflowStartTime (#476)
Fixes #462
1 parent 910fb1c commit b94084b

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/Temporalio/Worker/WorkflowInstance.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public WorkflowInstance(WorkflowInstanceDetails details)
198198
TaskQueue: details.TaskQueue,
199199
TaskTimeout: start.WorkflowTaskTimeout.ToTimeSpan(),
200200
WorkflowId: start.WorkflowId,
201+
WorkflowStartTime: start.StartTime.ToDateTime(),
201202
WorkflowType: start.WorkflowType);
202203
workflowStackTrace = details.WorkflowStackTrace;
203204
pendingTaskStackTraces = workflowStackTrace == WorkflowStackTrace.None ? null : new();

src/Temporalio/Workflows/WorkflowInfo.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ namespace Temporalio.Workflows
2323
/// versions or if there is no root (i.e. the root is itself).</param>
2424
/// <param name="RunId">Run ID for the workflow.</param>
2525
/// <param name="RunTimeout">Run timeout for the workflow.</param>
26-
/// <param name="StartTime">Time when the workflow started.</param>
26+
/// <param name="StartTime">Time when the first workflow task started.</param>
2727
/// <param name="TaskQueue">Task queue for the workflow.</param>
2828
/// <param name="TaskTimeout">Task timeout for the workflow.</param>
2929
/// <param name="WorkflowId">ID for the workflow.</param>
30+
/// <param name="WorkflowStartTime">Time when the workflow started on the server.</param>
3031
/// <param name="WorkflowType">Workflow type name.</param>
3132
/// <remarks>
3233
/// WARNING: This constructor may have required properties added. Do not rely on the exact
@@ -51,6 +52,7 @@ public record WorkflowInfo(
5152
string TaskQueue,
5253
TimeSpan TaskTimeout,
5354
string WorkflowId,
55+
DateTime WorkflowStartTime,
5456
string WorkflowType)
5557
{
5658
/// <summary>

tests/Temporalio.Tests/Worker/WorkflowWorkerTests.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ await ExecuteWorkerAsync<InfoWorkflow>(async worker =>
390390
(InfoWorkflow wf) => wf.RunAsync(),
391391
new(id: $"workflow-{Guid.NewGuid()}", taskQueue: worker.Options.TaskQueue!));
392392
var result = await handle.GetResultAsync();
393+
var history = await handle.FetchHistoryAsync();
393394
Assert.Equal(1, result.Attempt);
394395
Assert.Null(result.ContinuedRunId);
395396
Assert.Null(result.CronSchedule);
@@ -400,15 +401,19 @@ await ExecuteWorkerAsync<InfoWorkflow>(async worker =>
400401
Assert.Null(result.Root);
401402
Assert.Equal(handle.ResultRunId, result.RunId);
402403
Assert.Null(result.RunTimeout);
403-
Assert.InRange(
404-
result.StartTime,
405-
DateTime.UtcNow - TimeSpan.FromMinutes(5),
406-
DateTime.UtcNow + TimeSpan.FromMinutes(5));
407404
Assert.Equal(worker.Options.TaskQueue, result.TaskQueue);
408405
// TODO(cretz): Can assume default 10 in all test servers?
409406
Assert.Equal(TimeSpan.FromSeconds(10), result.TaskTimeout);
410407
Assert.Equal(handle.Id, result.WorkflowId);
411408
Assert.Equal("InfoWorkflow", result.WorkflowType);
409+
// Start time is the first task start time, but workflow start time is the actual start
410+
// time
411+
var workflowStartTime = history.Events.
412+
Single(e => e.WorkflowExecutionStartedEventAttributes != null).EventTime.ToDateTime();
413+
Assert.Equal(workflowStartTime, result.WorkflowStartTime);
414+
var firstTaskStartTime = history.Events.
415+
First(e => e.WorkflowTaskStartedEventAttributes != null).EventTime.ToDateTime();
416+
Assert.Equal(firstTaskStartTime, result.StartTime);
412417
});
413418
// Child info
414419
await ExecuteWorkerAsync<InfoFromChildWorkflow>(

0 commit comments

Comments
 (0)