Repository navigation
Expand file tree
/
Copy pathWorkflowStartOptions.php
More file actions
68 lines (59 loc) · 2.14 KB
/
Copy pathWorkflowStartOptions.php
File metadata and controls
68 lines (59 loc) · 2.14 KB
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
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
namespace Gplanchat\Durable;
/**
* Start options for a root execution (the counterpart of {@see ChildWorkflowOptions} for
* children).
*
* The metadata keys are deliberately identical to those of
* {@see ChildWorkflowOptions::toSchedulingMetadata()}: root and child describe the same
* settings, and the Temporal bridge reads them in the same place.
*/
final readonly class WorkflowStartOptions
{
/** The time bounds of the execution, taken together. */
public WorkflowTimeouts $timeouts;
/** What the execution will be findable by. */
public SearchAttributes $searchAttributes;
public function __construct(
/**
* Recurrence. The server starts an execution at every due time; the previous one must
* be finished, otherwise the due time is skipped.
*/
public ?CronSchedule $cronSchedule = null,
public ?TaskQueue $taskQueue = null,
?WorkflowTimeouts $timeouts = null,
public WorkflowIdReusePolicy $workflowIdReusePolicy = WorkflowIdReusePolicy::AllowDuplicateFailedOnly,
?SearchAttributes $searchAttributes = null,
) {
$this->timeouts = $timeouts ?? WorkflowTimeouts::none();
$this->searchAttributes = $searchAttributes ?? SearchAttributes::none();
}
public static function defaults(): self
{
return new self();
}
public static function cron(CronSchedule|string $schedule): self
{
return new self(cronSchedule: CronSchedule::from($schedule));
}
/**
* @return array<string, mixed>
*/
public function toStartMetadata(): array
{
$m = [];
if (null !== $this->cronSchedule) {
$m['cron_schedule'] = $this->cronSchedule->toExpression();
}
if (null !== $this->taskQueue) {
$m['task_queue'] = $this->taskQueue->name();
}
$m += $this->timeouts->toMetadata();
$m['workflow_id_reuse_policy'] = $this->workflowIdReusePolicy->value;
if (!$this->searchAttributes->isEmpty()) {
$m['search_attributes'] = $this->searchAttributes->toMetadata();
}
return $m;
}
}