summaryrefslogtreecommitdiff
path: root/tests/temporal/Activity/HeartBeatActivity.php
blob: acf4a45199615450f8085dca6952ce67025dfda0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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!';
    }
}