1818use LogicException ;
1919use Throwable ;
2020
21- abstract class ManagedTask implements ShouldQueue {
21+ abstract class ManagedSubTask implements ShouldQueue {
2222 use Batchable, Dispatchable, EnsuresTaskIsStarted, HasUpsert, InteractsWithQueue, Queueable, SerializesModels;
2323
2424 protected int $ taskId ;
@@ -35,7 +35,7 @@ abstract class ManagedTask implements ShouldQueue {
3535 * Sets subtask to processing
3636 * Sets subtask starting summary
3737 */
38- public function beginTask (TaskService $ taskService , string $ summary = '' ): bool {
38+ public function beginSubTask (TaskService $ taskService , string $ summary = '' ): bool {
3939 if (! $ this ->taskId ) {
4040 throw new LogicException ('Task ID missing, cannot begin task ' );
4141 }
@@ -63,7 +63,7 @@ public function beginTask(TaskService $taskService, string $summary = ''): bool
6363 return true ;
6464 }
6565
66- public function completeTask (TaskService $ taskService , string $ summary = '' , array $ taskCountUpdates = ['sub_tasks_complete ' => '++ ' ]): ?Task {
66+ public function completeSubTask (TaskService $ taskService , string $ summary = '' , array $ taskCountUpdates = ['sub_tasks_complete ' => '++ ' ]): ?Task {
6767 $ shouldBroadcastTaskUpdate = array_key_exists ('sub_tasks_total ' , $ taskCountUpdates );
6868
6969 $ endedAt = now ();
@@ -77,6 +77,8 @@ public function completeTask(TaskService $taskService, string $summary = '', arr
7777 'duration ' => $ duration ,
7878 ];
7979
80+ // TODO: This forces 100% completed state but this value should be calculated wait nevermind this is a subtask
81+
8082 DB ::transaction (function () use ($ taskService , $ taskCountUpdates , $ shouldBroadcastTaskUpdate , $ subTaskUpdates ) {
8183 $ taskService ->updateTaskCounts ($ this ->taskId , $ taskCountUpdates , $ shouldBroadcastTaskUpdate ); // TODO: Move broadcasts outside of updates?
8284 $ taskService ->updateSubTask ($ this ->subTaskId , $ subTaskUpdates );
@@ -85,7 +87,7 @@ public function completeTask(TaskService $taskService, string $summary = '', arr
8587 return Task::find ($ this ->taskId );
8688 }
8789
88- public function failTask (TaskService $ taskService , Throwable $ th ): void {
90+ public function failSubTask (TaskService $ taskService , Throwable $ th ): void {
8991 $ endedAt = now ();
9092 $ duration = $ this ->getTaskDuration ($ endedAt );
9193 $ subTaskUpdates = ['status ' => TaskStatus::FAILED , 'summary ' => 'Error: ' . $ th ->getMessage (), 'ended_at ' => $ endedAt , 'duration ' => $ duration ];
0 commit comments