diff options
Diffstat (limited to 'tests/temporal/Activity/HeartBeatActivity.php')
-rw-r--r-- | tests/temporal/Activity/HeartBeatActivity.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/temporal/Activity/HeartBeatActivity.php b/tests/temporal/Activity/HeartBeatActivity.php new file mode 100644 index 00000000..acf4a451 --- /dev/null +++ b/tests/temporal/Activity/HeartBeatActivity.php @@ -0,0 +1,58 @@ +<?php + +namespace Temporal\Tests\Activity; + +use Temporal\Activity; +use Temporal\Activity\ActivityInterface; +use Temporal\Activity\ActivityMethod; +use Temporal\Roadrunner\Internal\Error; + +#[ActivityInterface(prefix: "HeartBeatActivity.")] +class HeartBeatActivity +{ + #[ActivityMethod] + public function doSomething( + int $value + ): string { + Activity::heartbeat(['value' => $value]); + sleep($value); + return 'OK'; + } + + #[ActivityMethod] + public function slow( + string $value + ): string { + for ($i = 0; $i < 5; $i++) { + Activity::heartbeat(['value' => $i]); + sleep(1); + } + + return 'OK'; + } + + #[ActivityMethod] + public function something( + string $value + ): string { + Activity::heartbeat(['value' => $value]); + sleep($value); + return 'OK'; + } + + #[ActivityMethod] + public function failedActivity( + int $value + ): string { + Activity::heartbeat(['value' => $value]); + if (Activity::getInfo()->attempt === 1) { + throw new \Error("failed"); + } + + if (!is_array(Activity::getHeartbeatDetails())) { + throw new \Error("no heartbeat details"); + } + + return 'OK!'; + } +}
\ No newline at end of file |