Skip to content

Commit 7e4ae92

Browse files
authored
feat: expose FirstRunID & OriginalRunID in WorkflowInfo (#691)
* feat: expose FirstRunID & OriginalRunID in WorkflowInfo * chore: remove unused class import * test: fix marshalling tests
1 parent 10008d5 commit 7e4ae92

4 files changed

Lines changed: 81 additions & 14 deletions

File tree

src/Workflow/WorkflowInfo.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ final class WorkflowInfo
103103
#[Marshal(name: 'ContinuedExecutionRunID')]
104104
public ?string $continuedExecutionRunId = null;
105105

106+
#[Marshal(name: 'FirstRunID')]
107+
public ?string $firstExecutionRunId = null;
108+
109+
#[Marshal(name: 'OriginalRunID')]
110+
public ?string $originalExecutionRunId = null;
111+
106112
#[Marshal(name: 'ParentWorkflowNamespace')]
107113
public ?string $parentNamespace = null;
108114

tests/Acceptance/Extra/Workflow/WorkflowInfoTest.php

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,59 @@ class WorkflowInfoTest extends TestCase
1717
{
1818
#[Test]
1919
public static function rootWorkflowExecution(
20-
#[Stub('Extra_Workflow_WorkflowInfo', args: [MainWorkflow::ARG_ROOT_EXECUTION])]
20+
#[Stub('Extra_Workflow_WorkflowInfo', args: [[MainWorkflow::ARG_ROOT_EXECUTION]])]
2121
WorkflowStubInterface $stub,
2222
): void {
2323
$result = $stub->getResult(type: 'array');
2424
self::assertSame([
25-
'ID' => $stub->getExecution()->getID(),
26-
'RunID' => $stub->getExecution()->getRunID(),
27-
], $result);
25+
'id' => $stub->getExecution()->getID(),
26+
'runID' => $stub->getExecution()->getRunID(),
27+
], $result['rootExecution']);
28+
}
29+
30+
#[Test]
31+
public static function continueAsNewExecution(
32+
#[Stub('Extra_Workflow_WorkflowInfo', args: [[
33+
MainWorkflow::ARG_CONTINUE_AS_NEW,
34+
MainWorkflow::ARG_DUMP,
35+
]])]
36+
WorkflowStubInterface $stub,
37+
): void {
38+
$result = $stub->getResult(type: 'array');
39+
self::assertNotEmpty($result['continuedExecutionRunId']);
40+
self::assertSame($result['firstExecutionRunId'], $result['continuedExecutionRunId']);
41+
self::assertNotSame($result['firstExecutionRunId'], $result['originalExecutionRunId']);
42+
}
43+
44+
#[Test]
45+
public static function continueAsNewExecutionChild(
46+
#[Stub('Extra_Workflow_WorkflowInfo', args: [[
47+
MainWorkflow::ARG_CONTINUE_AS_NEW,
48+
MainWorkflow::ARG_RUN_MAIN_AS_CHILD,
49+
MainWorkflow::ARG_DUMP,
50+
]])]
51+
WorkflowStubInterface $stub,
52+
): void {
53+
$result = $stub->getResult(type: 'array');
54+
/**
55+
* There is no information about continued execution in child workflows.
56+
*/
57+
self::assertEmpty($result['continuedExecutionRunId']);
58+
self::assertIsString($result['continuedExecutionRunId']);
59+
self::assertSame($result['firstExecutionRunId'], $result['originalExecutionRunId']);
2860
}
2961

3062
#[Test]
3163
public static function retryOptions(
32-
#[Stub('Extra_Workflow_WorkflowInfo', args: [MainWorkflow::ARG_RETRY_OPTIONS], retryOptions: new RetryOptions(
33-
backoffCoefficient: 3.0,
34-
maximumInterval: '2 minutes',
35-
maximumAttempts: 10,
36-
))]
64+
#[Stub(
65+
'Extra_Workflow_WorkflowInfo',
66+
args: [[MainWorkflow::ARG_RETRY_OPTIONS]],
67+
retryOptions: new RetryOptions(
68+
backoffCoefficient: 3.0,
69+
maximumInterval: '2 minutes',
70+
maximumAttempts: 10,
71+
),
72+
)]
3773
WorkflowStubInterface $stub,
3874
): void {
3975
$result = $stub->getResult(type: 'array');
@@ -52,13 +88,20 @@ class MainWorkflow
5288
{
5389
public const ARG_RETRY_OPTIONS = 'retryPolicy';
5490
public const ARG_ROOT_EXECUTION = 'rootExecution';
91+
public const ARG_CONTINUE_AS_NEW = 'continueAsNew';
92+
public const ARG_DUMP = 'dump';
93+
public const ARG_RUN_MAIN_AS_CHILD = 'runMainAsChild';
5594

5695
#[WorkflowMethod('Extra_Workflow_WorkflowInfo')]
57-
public function run($arg)
96+
public function run(array $actions)
5897
{
59-
return yield match ($arg) {
98+
$action = \array_shift($actions);
99+
return yield match ($action) {
60100
self::ARG_ROOT_EXECUTION => Workflow::newChildWorkflowStub(ChildWorkflow::class)->run(),
61-
self::ARG_RETRY_OPTIONS => Workflow::getCurrentContext()->getInfo()->retryOptions,
101+
self::ARG_RETRY_OPTIONS => Workflow::getInfo()->retryOptions,
102+
self::ARG_CONTINUE_AS_NEW => Workflow::continueAsNew('Extra_Workflow_WorkflowInfo', args: [$actions]),
103+
self::ARG_RUN_MAIN_AS_CHILD => Workflow::newChildWorkflowStub(MainWorkflow::class)->run($actions),
104+
self::ARG_DUMP => Helper::dumpWorkflow(),
62105
};
63106
}
64107
}
@@ -79,6 +122,23 @@ class ChildWorkflow2
79122
#[WorkflowMethod('Extra_Workflow_WorkflowInfo_Child2')]
80123
public function run()
81124
{
82-
return Workflow::getCurrentContext()->getInfo()->rootExecution;
125+
return Helper::dumpWorkflow();
126+
}
127+
}
128+
129+
class Helper
130+
{
131+
public static function dumpWorkflow(): array
132+
{
133+
$workflowInfo = Workflow::getInfo();
134+
return [
135+
'rootExecution' => [
136+
'id' => $workflowInfo->rootExecution?->getID(),
137+
'runID' => $workflowInfo->rootExecution?->getRunID(),
138+
],
139+
'firstExecutionRunId' => $workflowInfo->firstExecutionRunId,
140+
'continuedExecutionRunId' => $workflowInfo->continuedExecutionRunId,
141+
'originalExecutionRunId' => $workflowInfo->originalExecutionRunId,
142+
];
83143
}
84144
}

tests/Functional/NamedArgumentsTestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Temporal\Client\GRPC\ServiceClient;
88
use Temporal\Client\WorkflowClient;
99
use Temporal\Client\WorkflowOptions;
10-
use Temporal\Tests\Workflow\ContinuableWorkflow;
1110
use Temporal\Tests\Workflow\ContinuaWithTaskQueueWorkflow;
1211
use Temporal\Tests\Workflow\NamedArguments\ContinueAsNewNamedArgumentsWorkflow;
1312
use Temporal\Tests\Workflow\NamedArguments\ExecuteChildNamedArgumentsWorkflow;

tests/Unit/DTO/WorkflowInfoTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function testMarshalling(): void
4141
'ShouldContinueAsNew' => false,
4242
'CronSchedule' => null,
4343
'ContinuedExecutionRunID' => null,
44+
'FirstRunID' => null,
45+
'OriginalRunID' => null,
4446
'ParentWorkflowNamespace' => null,
4547
'RootWorkflowExecution' => null,
4648
'ParentWorkflowExecution' => null,

0 commit comments

Comments
 (0)