Skip to content

Commit

Permalink
Merge pull request #471: Fix TaskQueue inheritance when workflow is c…
Browse files Browse the repository at this point in the history
…ontinued as new
  • Loading branch information
roxblnfk authored Jul 2, 2024
2 parents cfea7f0 + c470f2c commit adcfc27
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@
$request = new SignalExternalWorkflow(
$this->getOptions()->namespace,
$execution->getID(),
$execution->getRunID(),
null,
$name,
EncodedValues::fromValues($args),
true,
Expand Down
7 changes: 7 additions & 0 deletions src/Workflow/ContinueAsNewOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Temporal\Internal\Support\DateInterval;
use Temporal\Worker\WorkerFactoryInterface;
use Temporal\Worker\Worker;
use Temporal\Workflow;

/**
* @psalm-import-type DateIntervalValue from DateInterval
Expand Down Expand Up @@ -55,6 +56,12 @@ public function __construct()
{
$this->workflowRunTimeout = CarbonInterval::seconds(0);
$this->workflowTaskTimeout = CarbonInterval::seconds(0);
try {
// Inherit TaskQueue from the current Workflow if possible
$this->taskQueue = Workflow::getInfo()->taskQueue;
} catch (\Throwable) {
// Do nothing
}
}

/**
Expand Down
46 changes: 46 additions & 0 deletions tests/Fixtures/src/Workflow/ContinuaWithTaskQueueWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* This file is part of Temporal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Temporal\Tests\Workflow;

use Temporal\Activity\ActivityOptions;
use Temporal\Tests\Activity\SimpleActivity;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowMethod;

#[Workflow\WorkflowInterface]
class ContinuaWithTaskQueueWorkflow
{
#[WorkflowMethod(name: 'ContinuaWithTaskQueueWorkflow')]
public function handler(
int $generation
) {
$simple = Workflow::newActivityStub(
SimpleActivity::class,
ActivityOptions::new()->withStartToCloseTimeout(5)
);

if ($generation > 5) {
// complete
return Workflow::getInfo()->taskQueue . $generation;
}

if ($generation !== 1) {
assert(!empty(Workflow::getInfo()->continuedExecutionRunId));
}

for ($i = 0; $i < $generation; $i++) {
yield $simple->echo((string)$generation);
}

return Workflow::newContinueAsNewStub(self::class)->handler(++$generation);
}
}
21 changes: 21 additions & 0 deletions tests/Functional/NamedArgumentsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Temporal\Client\GRPC\ServiceClient;
use Temporal\Client\WorkflowClient;
use Temporal\Client\WorkflowOptions;
use Temporal\Tests\Workflow\ContinuableWorkflow;
use Temporal\Tests\Workflow\ContinuaWithTaskQueueWorkflow;
use Temporal\Tests\Workflow\NamedArguments\ContinueAsNewNamedArgumentsWorkflow;
use Temporal\Tests\Workflow\NamedArguments\ExecuteChildNamedArgumentsWorkflow;
use Temporal\Tests\Workflow\NamedArguments\ActivityNamedArgumentsWorkflow;
Expand Down Expand Up @@ -213,6 +216,24 @@ public function testContinueAsNewNamedArguments()
], $result);
}

/**
* TaskQueue must be inherited from the parent workflow
*/
public function testContinueAsNewTaskQueue(): void
{
$workflow = $this->workflowClient->newWorkflowStub(
ContinuaWithTaskQueueWorkflow::class,
WorkflowOptions::new()->withTaskQueue('FooBar'),
);

$result = $this->workflowClient->start(
$workflow,
generation: 1,
)->getResult();

self::assertSame('FooBar6', $result);
}

public function testExecuteChildNamedArguments()
{
$this->markTestSkipped(
Expand Down

0 comments on commit adcfc27

Please sign in to comment.