Skip to content

Commit bea2675

Browse files
committed
refactor(core): add TickInfo::applyTo and adopt it in command routers
Replace manual historyLength/historySize/shouldContinueAsNew assignments across Client and the Invoke*/StartWorkflow routers with a single TickInfo::applyTo(WorkflowInfo). Covered by TickInfoTestCase.
1 parent 50511c2 commit bea2675

7 files changed

Lines changed: 62 additions & 35 deletions

File tree

src/Internal/Transport/Client.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ public function dispatch(ServerResponseInterface $response): void
6060

6161
$info = $context->getInfo();
6262
if ($info !== null && $response->getTickInfo()->historyLength > $info->historyLength) {
63-
$tickInfo = $response->getTickInfo();
64-
/** @psalm-suppress InaccessibleProperty */
65-
$info->historyLength = $tickInfo->historyLength;
66-
/** @psalm-suppress InaccessibleProperty */
67-
$info->historySize = $tickInfo->historySize;
68-
/** @psalm-suppress InaccessibleProperty */
69-
$info->shouldContinueAsNew = $tickInfo->continueAsNewSuggested;
63+
$response->getTickInfo()->applyTo($info);
7064
}
7165

7266
// Bind workflow context for promise resolution

src/Internal/Transport/Router/InvokeQuery.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,7 @@ static function () use ($name, $request, $resolver, $handler, $context, $headers
8080
Workflow::setCurrentContext($context);
8181

8282
$info = $context->getInfo();
83-
$tickInfo = $request->getTickInfo();
84-
/** @psalm-suppress InaccessibleProperty */
85-
$info->historyLength = $tickInfo->historyLength;
86-
/** @psalm-suppress InaccessibleProperty */
87-
$info->historySize = $tickInfo->historySize;
88-
/** @psalm-suppress InaccessibleProperty */
89-
$info->shouldContinueAsNew = $tickInfo->continueAsNewSuggested;
83+
$request->getTickInfo()->applyTo($info);
9084

9185
$result = $handler(new QueryInput($name, $request->getPayloads(), $info));
9286
$resolver->resolve(EncodedValues::fromValues([$result]));

src/Internal/Transport/Router/InvokeSignal.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@ public function handle(ServerRequestInterface $request, array $headers, Deferred
3535
$context = $this->findProcessOrFail($requestId)->getContext();
3636

3737
$info = $context->getInfo();
38-
$tickInfo = $request->getTickInfo();
39-
/** @psalm-suppress InaccessibleProperty */
40-
$info->historyLength = $tickInfo->historyLength;
41-
/** @psalm-suppress InaccessibleProperty */
42-
$info->historySize = $tickInfo->historySize;
43-
/** @psalm-suppress InaccessibleProperty */
44-
$info->shouldContinueAsNew = $tickInfo->continueAsNewSuggested;
38+
$request->getTickInfo()->applyTo($info);
4539

4640
$handler($request->getPayloads());
4741

src/Internal/Transport/Router/InvokeUpdate.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ public function handle(ServerRequestInterface $request, array $headers, Deferred
3838
$handler = $this->getUpdateHandler($updateDispatcher, $name);
3939

4040
$info = $context->getInfo();
41-
$tickInfo = $request->getTickInfo();
42-
/** @psalm-suppress InaccessibleProperty */
43-
$info->historyLength = $tickInfo->historyLength;
44-
/** @psalm-suppress InaccessibleProperty */
45-
$info->historySize = $tickInfo->historySize;
46-
/** @psalm-suppress InaccessibleProperty */
47-
$info->shouldContinueAsNew = $tickInfo->continueAsNewSuggested;
41+
$request->getTickInfo()->applyTo($info);
4842

4943
$input = new UpdateInput(
5044
updateName: $name,

src/Internal/Transport/Router/StartWorkflow.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,7 @@ public function handle(ServerRequestInterface $request, array $headers, Deferred
7070
$input->header = $request->getHeader();
7171

7272
$info = $input->info;
73-
$tickInfo = $request->getTickInfo();
74-
/** @psalm-suppress InaccessibleProperty */
75-
$info->historyLength = $tickInfo->historyLength;
76-
/** @psalm-suppress InaccessibleProperty */
77-
$info->historySize = $tickInfo->historySize;
78-
/** @psalm-suppress InaccessibleProperty */
79-
$info->shouldContinueAsNew = $tickInfo->continueAsNewSuggested;
73+
$request->getTickInfo()->applyTo($info);
8074

8175
$instance = $this->instantiator->instantiate($this->findWorkflowOrFail($input->info));
8276

src/Worker/Transport/Command/Server/TickInfo.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Temporal\Worker\Transport\Command\Server;
1313

14+
use Temporal\Workflow\WorkflowInfo;
15+
1416
final class TickInfo
1517
{
1618
/**
@@ -24,4 +26,14 @@ public function __construct(
2426
public readonly bool $continueAsNewSuggested = false,
2527
public readonly bool $isReplaying = false,
2628
) {}
29+
30+
/**
31+
* @psalm-suppress InaccessibleProperty
32+
*/
33+
public function applyTo(WorkflowInfo $info): void
34+
{
35+
$info->historyLength = $this->historyLength;
36+
$info->historySize = $this->historySize;
37+
$info->shouldContinueAsNew = $this->continueAsNewSuggested;
38+
}
2739
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Temporal\Tests\Unit\Worker\Transport\Command\Server;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use Temporal\Tests\Unit\AbstractUnit;
9+
use Temporal\Worker\Transport\Command\Server\TickInfo;
10+
use Temporal\Workflow\WorkflowInfo;
11+
12+
#[CoversClass(TickInfo::class)]
13+
final class TickInfoTestCase extends AbstractUnit
14+
{
15+
public function testApplyToCopiesHistoryAndContinueAsNew(): void
16+
{
17+
$info = new WorkflowInfo();
18+
$tick = new TickInfo(
19+
time: new \DateTimeImmutable('2026-01-01T00:00:00+00:00'),
20+
historyLength: 42,
21+
historySize: 1024,
22+
continueAsNewSuggested: true,
23+
);
24+
25+
$tick->applyTo($info);
26+
27+
self::assertSame(42, $info->historyLength);
28+
self::assertSame(1024, $info->historySize);
29+
self::assertTrue($info->shouldContinueAsNew);
30+
}
31+
32+
public function testApplyToOverwritesPreviousValues(): void
33+
{
34+
$info = new WorkflowInfo();
35+
$info->historyLength = 99;
36+
$info->historySize = 99;
37+
$info->shouldContinueAsNew = true;
38+
39+
(new TickInfo(time: new \DateTimeImmutable('2026-01-01T00:00:00+00:00')))->applyTo($info);
40+
41+
self::assertSame(0, $info->historyLength);
42+
self::assertSame(0, $info->historySize);
43+
self::assertFalse($info->shouldContinueAsNew);
44+
}
45+
}

0 commit comments

Comments
 (0)