Skip to content

Commit 9a5919a

Browse files
authored
Expose summary option for timers and activities (#626)
2 parents 92ecec8 + 17749ec commit 9a5919a

34 files changed

+308
-78
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"roadrunner-php/roadrunner-api-dto": "^1.12.0",
3535
"roadrunner-php/version-checker": "^1.0.1",
3636
"spiral/attributes": "^3.1.8",
37-
"spiral/roadrunner": "^2025.1.0",
37+
"spiral/roadrunner": "^2025.1.2",
3838
"spiral/roadrunner-cli": "^2.6",
3939
"spiral/roadrunner-kv": "^4.3.1",
4040
"spiral/roadrunner-worker": "^3.6.2",

dload.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
temp-dir="./runtime"
55
>
66
<actions>
7-
<download software="rr" version="^2025.1.0"/>
7+
<download software="rr" version="^2025.1.2"/>
88
<download software="temporal" version="^1.3-priority"/>
99
<download software="temporal-tests-server"/>
1010
</actions>

psalm-baseline.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,11 +1098,6 @@
10981098
<code><![CDATA[PromiseInterface]]></code>
10991099
</TooManyTemplateParams>
11001100
</file>
1101-
<file src="src/Internal/Transport/Request/NewTimer.php">
1102-
<PossiblyNullPropertyFetch>
1103-
<code><![CDATA[CarbonInterval::make($interval)->totalMilliseconds]]></code>
1104-
</PossiblyNullPropertyFetch>
1105-
</file>
11061101
<file src="src/Internal/Transport/Router/CancelWorkflow.php">
11071102
<DocblockTypeContradiction>
11081103
<code><![CDATA[$process === null]]></code>

src/Activity/ActivityOptions.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ class ActivityOptions extends Options implements ActivityOptionsInterface
119119
#[Marshal(name: 'Priority')]
120120
public Priority $priority;
121121

122+
/**
123+
* Optional summary of the activity.
124+
*
125+
* Single-line fixed summary for this activity that will appear in UI/CLI.
126+
* This can be in single-line Temporal Markdown format.
127+
*
128+
* @experimental This API is experimental and may change in the future.
129+
*
130+
* @since RoadRunner 2025.1.2
131+
*/
132+
#[Marshal(name: 'Summary')]
133+
public string $summary = '';
134+
122135
/**
123136
* ActivityOptions constructor.
124137
*/
@@ -320,4 +333,22 @@ public function withPriority(Priority $priority): self
320333
$self->priority = $priority;
321334
return $self;
322335
}
336+
337+
/**
338+
* Optional summary of the activity.
339+
*
340+
* Single-line fixed summary for this activity that will appear in UI/CLI.
341+
* This can be in single-line Temporal Markdown format.
342+
*
343+
* @experimental This API is experimental and may change in the future.
344+
*
345+
* @return $this
346+
*/
347+
#[Pure]
348+
public function withSummary(string $summary): self
349+
{
350+
$self = clone $this;
351+
$self->summary = $summary;
352+
return $self;
353+
}
323354
}

src/Interceptor/WorkflowOutboundCalls/TimerInput.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Temporal\Interceptor\WorkflowOutboundCalls;
1313

14+
use Temporal\Workflow\TimerOptions;
15+
1416
/**
1517
* @psalm-immutable
1618
*/
@@ -22,13 +24,19 @@ final class TimerInput
2224
*/
2325
public function __construct(
2426
public readonly \DateInterval $interval,
27+
28+
/**
29+
* @experimental This API is experimental and may change in the future.
30+
*/
31+
public readonly ?TimerOptions $timerOptions,
2532
) {}
2633

2734
public function with(
2835
?\DateInterval $interval = null,
2936
): self {
3037
return new self(
3138
$interval ?? $this->interval,
39+
$this->timerOptions,
3240
);
3341
}
3442
}

src/Internal/Transport/Request/NewTimer.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Temporal\Internal\Transport\Request;
1313

1414
use Carbon\CarbonInterval;
15+
use Temporal\Internal\Workflow\AwaitOptions;
1516
use Temporal\Worker\Transport\Command\Client\Request;
1617

1718
/**
@@ -21,13 +22,29 @@ final class NewTimer extends Request
2122
{
2223
public const NAME = 'NewTimer';
2324

24-
public function __construct(private \DateInterval $interval)
25-
{
26-
parent::__construct(self::NAME, ['ms' => (int) CarbonInterval::make($interval)->totalMilliseconds]);
25+
public function __construct(
26+
private readonly AwaitOptions $awaitOptions,
27+
) {
28+
$options = [
29+
'ms' => (int) CarbonInterval::make($awaitOptions->interval)?->totalMilliseconds,
30+
];
31+
if ($this->awaitOptions->options !== null) {
32+
$options['summary'] = $this->awaitOptions->options->summary;
33+
}
34+
35+
parent::__construct(self::NAME, $options);
2736
}
2837

38+
/**
39+
* @deprecated use {@see getAwaitOptions()} instead.
40+
*/
2941
public function getInterval(): \DateInterval
3042
{
31-
return $this->interval;
43+
return $this->awaitOptions->interval;
44+
}
45+
46+
public function getAwaitOptions(): AwaitOptions
47+
{
48+
return $this->awaitOptions;
3249
}
3350
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\Internal\Workflow;
13+
14+
use Temporal\Workflow\TimerOptions;
15+
16+
/**
17+
* @internal
18+
* @experimental This API is experimental and may change in the future.
19+
*/
20+
class AwaitOptions
21+
{
22+
public function __construct(
23+
/**
24+
* Await timeout.
25+
*/
26+
public readonly \DateInterval $interval,
27+
28+
/**
29+
* Options set for the underlying timer created.
30+
*/
31+
public readonly ?TimerOptions $options,
32+
) {}
33+
}

src/Internal/Workflow/WorkflowContext.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
use Temporal\Workflow\ContinueAsNewOptions;
7373
use Temporal\Workflow\ExternalWorkflowStubInterface;
7474
use Temporal\Workflow\Mutex;
75+
use Temporal\Workflow\TimerOptions;
7576
use Temporal\Workflow\WorkflowContextInterface;
7677
use Temporal\Workflow\WorkflowExecution;
7778
use Temporal\Workflow\WorkflowInfo;
@@ -455,15 +456,17 @@ public function newActivityStub(
455456
);
456457
}
457458

458-
public function timer($interval): PromiseInterface
459+
public function timer($interval, ?TimerOptions $options = null): PromiseInterface
459460
{
460461
$dateInterval = DateInterval::parse($interval, DateInterval::FORMAT_SECONDS);
461462

462463
return $this->callsInterceptor->with(
463-
fn(TimerInput $input): PromiseInterface => $this->request(new NewTimer($input->interval)),
464+
fn(TimerInput $input): PromiseInterface => $this->request(
465+
new NewTimer(new AwaitOptions($input->interval, $options)),
466+
),
464467
/** @see WorkflowOutboundCallsInterceptor::timer() */
465468
'timer',
466-
)(new TimerInput($dateInterval));
469+
)(new TimerInput($dateInterval, $options));
467470
}
468471

469472
public function request(
@@ -606,7 +609,7 @@ public function awaitWithTimeout($interval, callable|Mutex|PromiseInterface ...$
606609
return $this->callsInterceptor->with(
607610
function (AwaitWithTimeoutInput $input): PromiseInterface {
608611
/** Bypassing {@see timer()} to acquire a timer request ID */
609-
$request = new NewTimer($input->interval);
612+
$request = new NewTimer(new AwaitOptions($input->interval, null));
610613
$requestId = $request->getID();
611614
$timer = $this->request($request);
612615
\assert($timer instanceof CompletableResultInterface);

src/Workflow.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Temporal\Workflow\ExternalWorkflowStubInterface;
3333
use Temporal\Workflow\Mutex;
3434
use Temporal\Workflow\ScopedContextInterface;
35+
use Temporal\Workflow\TimerOptions;
3536
use Temporal\Workflow\UpdateContext;
3637
use Temporal\Workflow\WorkflowContextInterface;
3738
use Temporal\Workflow\WorkflowExecution;
@@ -578,9 +579,9 @@ public static function sideEffect(callable $value): PromiseInterface
578579
* @return PromiseInterface<null>
579580
* @throws OutOfContextException in the absence of the workflow execution context.
580581
*/
581-
public static function timer($interval): PromiseInterface
582+
public static function timer($interval, ?TimerOptions $options = null): PromiseInterface
582583
{
583-
return self::getCurrentContext()->timer($interval);
584+
return self::getCurrentContext()->timer($interval, $options);
584585
}
585586

586587
/**

src/Workflow/TimerOptions.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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\Workflow;
13+
14+
use Temporal\Internal\Traits\CloneWith;
15+
16+
/**
17+
* TimerOptions is used to specify options for a timer.
18+
*
19+
* @experimental This API is experimental and may change in the future.
20+
*/
21+
final class TimerOptions
22+
{
23+
use CloneWith;
24+
25+
public readonly string $summary;
26+
27+
private function __construct()
28+
{
29+
$this->summary = '';
30+
}
31+
32+
public static function new(): self
33+
{
34+
return new self();
35+
}
36+
37+
/**
38+
* Single-line fixed summary for this timer that will appear in UI/CLI.
39+
*
40+
* This can be in single-line Temporal Markdown format.
41+
*/
42+
public function withSummary(string $summary): self
43+
{
44+
/** @see self::$summary */
45+
return $this->with('summary', $summary);
46+
}
47+
}

0 commit comments

Comments
 (0)