1111use Temporal \Internal \Client \WorkflowProxy ;
1212use Temporal \Internal \Workflow \ChildWorkflowProxy ;
1313use Temporal \Sugar \Attribute \RetryPolicy ;
14+ use Temporal \Sugar \Attribute \TaskQueue ;
15+ use Temporal \Sugar \Internal \Attribute \AttributeCollection ;
1416use Temporal \Sugar \Internal \Attribute \AttributeForWorkflow ;
1517use Temporal \Sugar \Internal \Attribute \AttributeReader ;
1618use Temporal \Sugar \Internal \RetryOptions ;
@@ -28,7 +30,7 @@ final class WorkflowStub
2830 *
2931 * @param class-string<T> $workflow
3032 * @param non-empty-string|null $taskQueue
31- * @param int<0, max> $retryAttempts Maximum number of attempts. When exceeded the retries stop even
33+ * @param int<0, max>|null $retryAttempts Maximum number of attempts. When exceeded the retries stop even
3234 * if not expired yet. If not set or set to 0, it means unlimited, and rely on activity
3335 * {@see ActivityOptions::$scheduleToCloseTimeout} to stop.
3436 * @param DateInterval|string|int|null $retryInitInterval Backoff interval for the first retry.
@@ -77,7 +79,7 @@ public static function workflow(
7779 WorkflowClientInterface $ workflowClient ,
7880 string $ workflow ,
7981 ?string $ taskQueue = null ,
80- int $ retryAttempts = 0 ,
82+ ? int $ retryAttempts = null ,
8183 \DateInterval |string |int |null $ retryInitInterval = null ,
8284 \DateInterval |string |int |null $ retryMaxInterval = null ,
8385 ?float $ retryBackoff = null ,
@@ -102,11 +104,11 @@ public static function workflow(
102104 retryMaxInterval: $ retryMaxInterval ,
103105 retryBackoff: $ retryBackoff ,
104106 nonRetryables: $ nonRetryables ,
105- attribute: $ attributes[ RetryPolicy::class] ?? null ,
107+ attribute: $ attributes-> first ( RetryPolicy::class) ,
106108 );
107109
108110 $ options = WorkflowOptions::new ()->withRetryOptions ($ retryOptions );
109- $ taskQueue === null or $ options = $ options -> withTaskQueue ( $ taskQueue ) ;
111+ $ taskQueue ??= $ attributes -> first (TaskQueue::class)?->name ;
110112 // Start options
111113 $ startDelay === 0 or $ options = $ options ->withWorkflowStartDelay ($ startDelay );
112114 $ eagerStart and $ options = $ options ->withEagerStart (true );
@@ -135,7 +137,7 @@ public static function workflow(
135137 * @param non-empty-string|null $taskQueue Task queue to use for workflow tasks. It should match a task queue
136138 * specified when creating a {@see Worker} that hosts the workflow code.
137139 * @param non-empty-string|null $namespace Specify namespace in which workflow should be started.
138- * @param int<0, max> $retryAttempts Maximum number of attempts. When exceeded the retries stop even
140+ * @param int<0, max>|null $retryAttempts Maximum number of attempts. When exceeded the retries stop even
139141 * if not expired yet. If not set or set to 0, it means unlimited, and rely on activity
140142 * {@see ActivityOptions::$scheduleToCloseTimeout} to stop.
141143 * @param DateInterval|string|int|null $retryInitInterval Backoff interval for the first retry.
@@ -178,7 +180,7 @@ public static function childWorkflow(
178180 string $ workflow ,
179181 ?string $ taskQueue = null ,
180182 ?string $ namespace = null ,
181- int $ retryAttempts = 0 ,
183+ ? int $ retryAttempts = null ,
182184 \DateInterval |string |int |null $ retryInitInterval = null ,
183185 \DateInterval |string |int |null $ retryMaxInterval = null ,
184186 ?float $ retryBackoff = null ,
@@ -194,17 +196,21 @@ public static function childWorkflow(
194196 array $ searchAttributes = [],
195197 array $ memo = [],
196198 ): object {
199+ $ attributes = self ::readAttributes ($ workflow );
200+
197201 // Retry options
198202 $ retryOptions = RetryOptions::create (
199203 $ retryAttempts ,
200204 $ retryInitInterval ,
201205 $ retryMaxInterval ,
202206 $ retryBackoff ,
203207 $ nonRetryables ,
208+ attribute: $ attributes ->first (RetryPolicy::class),
204209 );
205210
206211 $ options = Workflow \ChildWorkflowOptions::new ()->withRetryOptions ($ retryOptions );
207212
213+ $ taskQueue ??= $ attributes ->first (TaskQueue::class)?->name;
208214 $ taskQueue === null or $ options = $ options ->withTaskQueue ($ taskQueue );
209215 $ namespace === null or $ options = $ options ->withNamespace ($ namespace );
210216 // Start and close options
@@ -230,11 +236,10 @@ public static function childWorkflow(
230236 }
231237
232238 /**
233- * @param class-string $class
234- * @return array<class-string<AttributeForWorkflow>, AttributeForWorkflow>
239+ * @param class-string $class Workflow class name.
235240 */
236- private static function readAttributes (string $ class ): array
241+ private static function readAttributes (string $ class ): AttributeCollection
237242 {
238- return AttributeReader::fromClass ($ class , [AttributeForWorkflow::class]);
243+ return AttributeReader::collectionFromClass ($ class , [AttributeForWorkflow::class]);
239244 }
240245}
0 commit comments