Skip to content

Commit 80b2ad1

Browse files
authored
Add new workflow info field for workflow_start_time (#866)
* Add new workflow info field for workflow_start_time * Alphabetical order
1 parent 257f143 commit 80b2ad1

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

temporalio/worker/_workflow.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,9 @@ def _create_workflow_instance(
532532
init.search_attributes
533533
),
534534
start_time=act.timestamp.ToDatetime().replace(tzinfo=timezone.utc),
535+
workflow_start_time=init.start_time.ToDatetime().replace(
536+
tzinfo=timezone.utc
537+
),
535538
task_queue=self._task_queue,
536539
task_timeout=init.workflow_task_timeout.ToTimedelta(),
537540
typed_search_attributes=temporalio.converter.decode_typed_search_attributes(

temporalio/worker/workflow_sandbox/_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
run_timeout=None,
4343
search_attributes={},
4444
start_time=datetime.fromtimestamp(0, timezone.utc),
45+
workflow_start_time=datetime.fromtimestamp(0, timezone.utc),
4546
task_queue="sandbox-validate-task_queue",
4647
task_timeout=timedelta(),
4748
typed_search_attributes=temporalio.common.TypedSearchAttributes.empty,

temporalio/workflow.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ class Info:
508508
"""
509509

510510
start_time: datetime
511+
"""The start time of the first task executed by the workflow."""
512+
511513
task_queue: str
512514
task_timeout: timedelta
513515

@@ -520,6 +522,10 @@ class Info:
520522
"""
521523

522524
workflow_id: str
525+
526+
workflow_start_time: datetime
527+
"""The start time of the workflow based on the workflow initialization."""
528+
523529
workflow_type: str
524530

525531
def _logger_details(self) -> Mapping[str, Any]:

tests/worker/test_workflow.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,13 @@ async def test_workflow_info(client: Client, env: WorkflowEnvironment):
220220
maximum_interval=timedelta(seconds=5),
221221
maximum_attempts=6,
222222
)
223-
info = await client.execute_workflow(
223+
handle = await client.start_workflow(
224224
InfoWorkflow.run,
225225
id=workflow_id,
226226
task_queue=worker.task_queue,
227227
retry_policy=retry_policy,
228228
)
229+
info = await handle.result()
229230
assert info["attempt"] == 1
230231
assert info["cron_schedule"] is None
231232
assert info["execution_timeout"] is None
@@ -235,12 +236,27 @@ async def test_workflow_info(client: Client, env: WorkflowEnvironment):
235236
)
236237
assert uuid.UUID(info["run_id"]).version == 7
237238
assert info["run_timeout"] is None
238-
datetime.fromisoformat(info["start_time"])
239239
assert info["task_queue"] == worker.task_queue
240240
assert info["task_timeout"] == "0:00:10"
241241
assert info["workflow_id"] == workflow_id
242242
assert info["workflow_type"] == "InfoWorkflow"
243243

244+
async for e in handle.fetch_history_events():
245+
if e.HasField("workflow_execution_started_event_attributes"):
246+
assert info["workflow_start_time"] == json.loads(
247+
json.dumps(
248+
e.event_time.ToDatetime().replace(tzinfo=timezone.utc),
249+
default=str,
250+
)
251+
)
252+
elif e.HasField("workflow_task_started_event_attributes"):
253+
assert info["start_time"] == json.loads(
254+
json.dumps(
255+
e.event_time.ToDatetime().replace(tzinfo=timezone.utc),
256+
default=str,
257+
)
258+
)
259+
244260

245261
@dataclass
246262
class HistoryInfo:

0 commit comments

Comments
 (0)