@@ -32,7 +32,7 @@ class AsyncTask
3232 * If null, the task will generate an unsaved random ID when it is started.
3333 * @var string|null
3434 */
35- protected string |null $ taskID ;
35+ private string |null $ taskID ;
3636
3737 /**
3838 * The process that is actually running this task. Tasks that are not started will have null here.
@@ -131,6 +131,18 @@ public function __unserialize($data): void
131131 ] = $ data ;
132132 }
133133
134+ /**
135+ * Returns a status object for the started AsyncTask.
136+ *
137+ * If this task does not have an explicit task ID, a new one will be generated on-the-fly.
138+ * @return AsyncTaskStatus The status object for the started AsyncTask.
139+ */
140+ protected function getTaskStatusObject (): AsyncTaskStatus
141+ {
142+ $ taskID = $ this ->taskID ?? Str::ulid ()->toString ();
143+ return new AsyncTaskStatus ($ taskID );
144+ }
145+
134146 /**
135147 * Inside an available PHP process, runs this AsyncTask instance.
136148 *
@@ -192,8 +204,7 @@ public function run(): void
192204 public function start (): AsyncTaskStatus
193205 {
194206 // prepare the task details
195- $ taskID = $ this ->taskID ?? Str::ulid ()->toString ();
196- $ taskStatus = new AsyncTaskStatus ($ taskID );
207+ $ taskStatus = $ this ->getTaskStatusObject ();
197208
198209 // prepare the runner command
199210 $ serializedTask = $ this ->toBase64Serial ();
0 commit comments