@@ -32,7 +32,7 @@ class AsyncTask
32
32
* If null, the task will generate an unsaved random ID when it is started.
33
33
* @var string|null
34
34
*/
35
- protected string |null $ taskID ;
35
+ private string |null $ taskID ;
36
36
37
37
/**
38
38
* 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
131
131
] = $ data ;
132
132
}
133
133
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
+
134
146
/**
135
147
* Inside an available PHP process, runs this AsyncTask instance.
136
148
*
@@ -192,8 +204,7 @@ public function run(): void
192
204
public function start (): AsyncTaskStatus
193
205
{
194
206
// prepare the task details
195
- $ taskID = $ this ->taskID ?? Str::ulid ()->toString ();
196
- $ taskStatus = new AsyncTaskStatus ($ taskID );
207
+ $ taskStatus = $ this ->getTaskStatusObject ();
197
208
198
209
// prepare the runner command
199
210
$ serializedTask = $ this ->toBase64Serial ();
0 commit comments