-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #331: Fix exceptions propagation from Signal methods
- Loading branch information
Showing
13 changed files
with
253 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?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 InvalidArgumentException; | ||
use Temporal\Activity\ActivityOptions; | ||
use Temporal\Common\RetryOptions; | ||
use Temporal\Workflow; | ||
use Temporal\Workflow\SignalMethod; | ||
use Temporal\Workflow\WorkflowInterface; | ||
use Temporal\Workflow\WorkflowMethod; | ||
|
||
#[WorkflowInterface] | ||
class SignalExceptionsWorkflow | ||
{ | ||
private array $greetings = []; | ||
private bool $exit = false; | ||
|
||
#[WorkflowMethod(name: "SignalExceptions.greet")] | ||
public function greet() | ||
{ | ||
$received = []; | ||
while (true) { | ||
yield Workflow::await(fn() => $this->greetings !== [] || $this->exit); | ||
if ($this->greetings === [] && $this->exit) { | ||
return $received; | ||
} | ||
|
||
$message = array_shift($this->greetings); | ||
$received[] = $message; | ||
} | ||
} | ||
|
||
#[SignalMethod] | ||
public function failWithName(string $name): void | ||
{ | ||
$this->greetings[] = $name; | ||
throw new \RuntimeException("Signal exception $name"); | ||
} | ||
|
||
#[SignalMethod] | ||
public function failInvalidArgument($name = 'foo'): void | ||
{ | ||
$this->greetings[] = "invalidArgument $name"; | ||
throw new InvalidArgumentException("Invalid argument $name"); | ||
} | ||
|
||
#[SignalMethod] | ||
public function failActivity($name = 'foo') | ||
{ | ||
yield Workflow::newUntypedActivityStub( | ||
ActivityOptions::new() | ||
->withScheduleToStartTimeout(1) | ||
->withRetryOptions( | ||
RetryOptions::new()->withMaximumAttempts(1) | ||
) | ||
->withStartToCloseTimeout(1), | ||
)->execute('nonExistingActivityName', [$name]); | ||
} | ||
|
||
#[SignalMethod] | ||
public function failRetryable() | ||
{ | ||
10 / 0; | ||
} | ||
|
||
#[SignalMethod] | ||
public function exit(): void | ||
{ | ||
$this->exit = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.