Skip to content

Commit d502782

Browse files
authored
Merge pull request #599: Fix collecting Workflow requests after destroying
2 parents 5e8c338 + c5603d4 commit d502782

File tree

22 files changed

+281
-77
lines changed

22 files changed

+281
-77
lines changed

.github/workflows/run-test-suite.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ jobs:
8585

8686
- name: Get Composer Cache Directory
8787
id: composer-cache
88-
run: |
89-
echo "::set-output name=dir::$(composer config cache-files-dir)"
88+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
9089

9190
- name: Cache Composer Dependencies
9291
uses: actions/cache@v3

.github/workflows/security-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030

3131
- name: Get Composer Cache Directory
3232
id: composer-cache
33-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
33+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
3434

3535
- name: Cache Dependencies
3636
uses: actions/cache@v3

.github/workflows/static-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030

3131
- name: Get Composer Cache Directory
3232
id: composer-cache
33-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
33+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
3434

3535
- name: Cache Dependencies
3636
uses: actions/cache@v3
@@ -68,7 +68,7 @@ jobs:
6868

6969
- name: Get Composer Cache Directory
7070
id: composer-cache
71-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
71+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
7272

7373
- name: Cache Dependencies
7474
uses: actions/cache@v3

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"composer/composer": "^2.8.4",
5757
"dereuromark/composer-prefer-lowest": "^0.1.10",
5858
"doctrine/annotations": "^1.14.4 || ^2.0.2",
59-
"internal/dload": "^1.0",
59+
"internal/dload": "^1.0.2",
6060
"jetbrains/phpstorm-attributes": "dev-master",
6161
"laminas/laminas-code": "^4.16",
6262
"phpunit/phpunit": "^10.5.41",

dload.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<?xml version="1.0"?>
2-
<dload>
2+
<dload xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/internal/dload/dload.xsd"
4+
temp-dir="./runtime"
5+
>
36
<actions>
4-
<download software="rr" version="^2024.2"/>
7+
<download software="rr" version="^2024.3.3"/>
58
<download software="temporal"/>
69
<download software="temporal-tests-server"/>
710
</actions>
811
<registry>
912
<software name="Temporal Tests Server" alias="temporal-tests-server">
1013
<repository type="github" uri="temporalio/sdk-java" asset-pattern="/^temporal-test-server.*/"/>
11-
<file pattern="/^(temporal-test-server)(?:\.exe)?$/" />
14+
<binary name="temporal-test-server"/>
1215
</software>
1316
</registry>
1417
</dload>

psalm-baseline.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,6 @@
14811481
<code><![CDATA[$codec]]></code>
14821482
</PropertyNotSetInConstructor>
14831483
<UndefinedInterfaceMethod>
1484-
<code><![CDATA[dispatch]]></code>
14851484
<code><![CDATA[dispatch]]></code>
14861485
<code><![CDATA[dispatch]]></code>
14871486
<code><![CDATA[update]]></code>

src/Client/Workflow/WorkflowExecutionDescription.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
* DTO that contains detailed information about Workflow Execution.
1212
*
1313
* @see \Temporal\Api\Workflowservice\V1\DescribeWorkflowExecutionResponse
14-
*
15-
* @internal
1614
*/
1715
final class WorkflowExecutionDescription
1816
{

src/Internal/Transport/Client.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,21 @@ public function reject(CommandInterface $command, \Throwable $reason): void
116116
$this->fetch($command->getID())->reject($reason);
117117
}
118118

119+
public function fork(): ClientInterface
120+
{
121+
return new DetachedClient($this, function (array $ids): void {
122+
foreach ($ids as $id) {
123+
unset($this->requests[$id]);
124+
}
125+
});
126+
}
127+
128+
public function destroy(): void
129+
{
130+
$this->requests = [];
131+
unset($this->queue);
132+
}
133+
119134
private function fetch(int $id): Deferred
120135
{
121136
$request = $this->get($id);

src/Internal/Transport/ClientInterface.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
namespace Temporal\Internal\Transport;
1313

1414
use React\Promise\PromiseInterface;
15+
use Temporal\Internal\Declaration\Destroyable;
1516
use Temporal\Worker\Transport\Command\CommandInterface;
1617
use Temporal\Worker\Transport\Command\RequestInterface;
18+
use Temporal\Worker\Transport\Command\ServerResponseInterface;
1719
use Temporal\Workflow\WorkflowContextInterface;
1820

19-
interface ClientInterface
21+
interface ClientInterface extends Destroyable
2022
{
2123
/**
2224
* Send a request and return a promise.
@@ -39,4 +41,14 @@ public function cancel(CommandInterface $command): void;
3941
* Reject pending promise.
4042
*/
4143
public function reject(CommandInterface $command, \Throwable $reason): void;
44+
45+
/**
46+
* Dispatch a response to the request.
47+
*/
48+
public function dispatch(ServerResponseInterface $response): void;
49+
50+
/**
51+
* Create a new client that can work with parent's request queue.
52+
*/
53+
public function fork(): ClientInterface;
4254
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Temporal package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Temporal\Internal\Transport;
13+
14+
use React\Promise\PromiseInterface;
15+
use Temporal\Worker\Transport\Command\CommandInterface;
16+
use Temporal\Worker\Transport\Command\RequestInterface;
17+
use Temporal\Worker\Transport\Command\ServerResponseInterface;
18+
use Temporal\Workflow\WorkflowContextInterface;
19+
20+
/**
21+
* @internal Client is an internal library class, please do not use it in your code.
22+
* @psalm-internal Temporal\Internal\Transport
23+
*/
24+
final class DetachedClient implements ClientInterface
25+
{
26+
/** @var list<int> */
27+
private array $requests = [];
28+
29+
/**
30+
* @param \Closure(list<int>): void $cleanup Handler that removes requests from the parent using their IDs.
31+
*/
32+
public function __construct(
33+
private ClientInterface $parent,
34+
private \Closure $cleanup,
35+
) {}
36+
37+
#[\Override]
38+
public function request(RequestInterface $request, ?WorkflowContextInterface $context = null): PromiseInterface
39+
{
40+
$this->requests[] = $request->getID();
41+
return $this->parent->request($request, $context);
42+
}
43+
44+
#[\Override]
45+
public function send(CommandInterface $request): void
46+
{
47+
$this->parent->send($request);
48+
}
49+
50+
#[\Override]
51+
public function isQueued(CommandInterface $command): bool
52+
{
53+
return $this->parent->isQueued($command);
54+
}
55+
56+
#[\Override]
57+
public function cancel(CommandInterface $command): void
58+
{
59+
$this->parent->cancel($command);
60+
}
61+
62+
#[\Override]
63+
public function reject(CommandInterface $command, \Throwable $reason): void
64+
{
65+
$this->parent->reject($command, $reason);
66+
}
67+
68+
#[\Override]
69+
public function dispatch(ServerResponseInterface $response): void
70+
{
71+
$this->parent->dispatch($response);
72+
}
73+
74+
#[\Override]
75+
public function fork(): ClientInterface
76+
{
77+
return $this->parent->fork();
78+
}
79+
80+
public function destroy(): void
81+
{
82+
$this->requests === [] or ($this->cleanup)($this->requests);
83+
$this->requests = [];
84+
unset($this->parent, $this->cleanup);
85+
}
86+
}

0 commit comments

Comments
 (0)