Skip to content

Commit adcfc27

Browse files
authored
Merge pull request #471: Fix TaskQueue inheritance when workflow is continued as new
2 parents cfea7f0 + c470f2c commit adcfc27

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

psalm-baseline.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@
12021202
$request = new SignalExternalWorkflow(
12031203
$this->getOptions()->namespace,
12041204
$execution->getID(),
1205-
$execution->getRunID(),
1205+
null,
12061206
$name,
12071207
EncodedValues::fromValues($args),
12081208
true,

src/Workflow/ContinueAsNewOptions.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Temporal\Internal\Support\DateInterval;
1919
use Temporal\Worker\WorkerFactoryInterface;
2020
use Temporal\Worker\Worker;
21+
use Temporal\Workflow;
2122

2223
/**
2324
* @psalm-import-type DateIntervalValue from DateInterval
@@ -55,6 +56,12 @@ public function __construct()
5556
{
5657
$this->workflowRunTimeout = CarbonInterval::seconds(0);
5758
$this->workflowTaskTimeout = CarbonInterval::seconds(0);
59+
try {
60+
// Inherit TaskQueue from the current Workflow if possible
61+
$this->taskQueue = Workflow::getInfo()->taskQueue;
62+
} catch (\Throwable) {
63+
// Do nothing
64+
}
5865
}
5966

6067
/**
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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\Tests\Workflow;
13+
14+
use Temporal\Activity\ActivityOptions;
15+
use Temporal\Tests\Activity\SimpleActivity;
16+
use Temporal\Workflow;
17+
use Temporal\Workflow\WorkflowMethod;
18+
19+
#[Workflow\WorkflowInterface]
20+
class ContinuaWithTaskQueueWorkflow
21+
{
22+
#[WorkflowMethod(name: 'ContinuaWithTaskQueueWorkflow')]
23+
public function handler(
24+
int $generation
25+
) {
26+
$simple = Workflow::newActivityStub(
27+
SimpleActivity::class,
28+
ActivityOptions::new()->withStartToCloseTimeout(5)
29+
);
30+
31+
if ($generation > 5) {
32+
// complete
33+
return Workflow::getInfo()->taskQueue . $generation;
34+
}
35+
36+
if ($generation !== 1) {
37+
assert(!empty(Workflow::getInfo()->continuedExecutionRunId));
38+
}
39+
40+
for ($i = 0; $i < $generation; $i++) {
41+
yield $simple->echo((string)$generation);
42+
}
43+
44+
return Workflow::newContinueAsNewStub(self::class)->handler(++$generation);
45+
}
46+
}

tests/Functional/NamedArgumentsTestCase.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
use Temporal\Client\GRPC\ServiceClient;
88
use Temporal\Client\WorkflowClient;
9+
use Temporal\Client\WorkflowOptions;
10+
use Temporal\Tests\Workflow\ContinuableWorkflow;
11+
use Temporal\Tests\Workflow\ContinuaWithTaskQueueWorkflow;
912
use Temporal\Tests\Workflow\NamedArguments\ContinueAsNewNamedArgumentsWorkflow;
1013
use Temporal\Tests\Workflow\NamedArguments\ExecuteChildNamedArgumentsWorkflow;
1114
use Temporal\Tests\Workflow\NamedArguments\ActivityNamedArgumentsWorkflow;
@@ -213,6 +216,24 @@ public function testContinueAsNewNamedArguments()
213216
], $result);
214217
}
215218

219+
/**
220+
* TaskQueue must be inherited from the parent workflow
221+
*/
222+
public function testContinueAsNewTaskQueue(): void
223+
{
224+
$workflow = $this->workflowClient->newWorkflowStub(
225+
ContinuaWithTaskQueueWorkflow::class,
226+
WorkflowOptions::new()->withTaskQueue('FooBar'),
227+
);
228+
229+
$result = $this->workflowClient->start(
230+
$workflow,
231+
generation: 1,
232+
)->getResult();
233+
234+
self::assertSame('FooBar6', $result);
235+
}
236+
216237
public function testExecuteChildNamedArguments()
217238
{
218239
$this->markTestSkipped(

0 commit comments

Comments
 (0)