77use Closure ;
88use Illuminate \Process \InvokedProcess ;
99use Illuminate \Support \Facades \Process ;
10+ use Illuminate \Support \Str ;
1011use Laravel \SerializableClosure \SerializableClosure ;
1112use LogicException ;
1213use loophp \phposinfo \OsInfo ;
@@ -159,10 +160,15 @@ public function run(): void
159160
160161 /**
161162 * Starts this AsyncTask immediately in the background. A runner will then run this AsyncTask.
162- * @return void
163+ * @return AsyncTaskStatus The status object for the started AsyncTask.
163164 */
164- public function start (): void
165+ public function start (): AsyncTaskStatus
165166 {
167+ // prepare the task details
168+ // todo allow changing the task ID
169+ $ taskID = null ?? Str::ulid ();
170+ $ taskStatus = new AsyncTaskStatus ($ taskID );
171+
166172 // prepare the runner command
167173 $ serializedTask = $ this ->toBase64Serial ();
168174 $ baseCommand = "php artisan async:run $ serializedTask " ;
@@ -173,7 +179,7 @@ public function start(): void
173179 // but we require cmd (ps won't work here), so might as well force cmd like this
174180 // windows has real max time limit
175181 $ this ->runnerProcess = Process::quietly ()->start ("cmd >nul 2>nul /c start /b $ baseCommand " );
176- return ;
182+ return $ taskStatus ;
177183 }
178184 // assume anything not windows to be unix
179185 // unix use nohup
@@ -197,6 +203,7 @@ public function start(): void
197203 $ timeoutClause = static ::$ timeoutCmdName . " -s 2 {$ this ->timeLimit }" ;
198204 }
199205 $ this ->runnerProcess = Process::quietly ()->start ("nohup $ timeoutClause $ baseCommand >/dev/null 2>&1 " );
206+ return $ taskStatus ;
200207 }
201208
202209 /**
0 commit comments