Skip to content

Commit acd7ec5

Browse files
committed
fix: managed task is a managed subtask and should be named as such
1 parent 7b2de04 commit acd7ec5

9 files changed

Lines changed: 40 additions & 38 deletions

app/Jobs/EmbedUidInMetadata.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Symfony\Component\Process\Process;
1313

1414
#[DeleteWhenMissingModels]
15-
class EmbedUidInMetadata extends ManagedTask {
15+
class EmbedUidInMetadata extends ManagedSubTask {
1616
protected $filePath;
1717

1818
protected $uuid;
@@ -41,11 +41,11 @@ public function __construct($filePath, $uuid, $taskId, $videoId = null) {
4141
* Execute the job.
4242
*/
4343
public function handle(TaskService $taskService): void {
44-
$this->beginTask($taskService, "Adding uuid to $this->filePath");
44+
$this->beginSubTask($taskService, "Adding uuid to $this->filePath");
4545

4646
try {
4747
$summary = $this->handleEmbed();
48-
$task = $this->completeTask($taskService, $summary);
48+
$task = $this->completeSubTask($taskService, $summary);
4949

5050
if ($this->videoId) {
5151
Video::where('id', $this->videoId)->update(['uuid' => $this->uuid]);
@@ -74,7 +74,7 @@ public function handle(TaskService $taskService): void {
7474
], $status === TaskStatus::COMPLETED);
7575
} catch (\Throwable $th) {
7676
dump($th->getMessage());
77-
$this->failTask($taskService, $th);
77+
$this->failSubTask($taskService, $th);
7878
if ($this->batch()) {
7979
// Batch error handling is in the job service
8080
throw $th;

app/Jobs/GeneratePreviewImage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use App\Services\PreviewGeneratorService;
99
use App\Services\TaskService;
1010

11-
class GeneratePreviewImage extends ManagedTask {
11+
class GeneratePreviewImage extends ManagedSubTask {
1212
protected $itemTitle;
1313

1414
public $timeout = 3600;
@@ -32,7 +32,7 @@ public function __construct(
3232
}
3333

3434
public function handle(PreviewGeneratorService $previewGenerator, TaskService $taskService) {
35-
if (! $this->beginTask($taskService)) {
35+
if (! $this->beginSubTask($taskService)) {
3636
return;
3737
}
3838

@@ -41,9 +41,9 @@ public function handle(PreviewGeneratorService $previewGenerator, TaskService $t
4141
if (! $result) {
4242
throw new GenerateImageException('Preview image generation failed. View logs for error.');
4343
}
44-
$this->completeTask($taskService, 'Generated preview image.');
44+
$this->completeSubTask($taskService, 'Generated preview image.');
4545
} catch (\Throwable $th) {
46-
$this->failTask($taskService, $th);
46+
$this->failSubTask($taskService, $th);
4747
throw $th;
4848
}
4949
}

app/Jobs/IndexFiles.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Illuminate\Support\Str;
1717
use Ramsey\Uuid\Uuid;
1818

19-
class IndexFiles extends ManagedTask {
19+
class IndexFiles extends ManagedSubTask {
2020
protected $taskService;
2121

2222
protected $embedChain = [];
@@ -39,23 +39,23 @@ public function __construct($taskId) {
3939
*/
4040
public function handle(TaskService $taskService): void {
4141
$this->taskService = $taskService; // Only for this job for compatibility since this will be re-written soon
42-
$this->beginTask($taskService, 'Starting Index Files');
42+
$this->beginSubTask($taskService, 'Starting Index Files');
4343

4444
dump('Starting Index Files');
4545

4646
try {
4747
$summary = $this->generateData();
4848
$taskCountUpdates = count($this->embedChain) ? ['sub_tasks_complete' => '++', 'sub_tasks_total' => count($this->embedChain), 'sub_tasks_current' => count($this->embedChain), 'sub_tasks_pending' => count($this->embedChain)] : ['sub_tasks_complete' => '++'];
4949

50-
$this->completeTask($taskService, $summary, $taskCountUpdates);
50+
$this->completeSubTask($taskService, $summary, $taskCountUpdates);
5151

5252
foreach ($this->embedChain as $embedTask) {
5353
$this->batch()->add($embedTask);
5454
}
5555
} catch (BatchCancelledException $e) {
5656
$taskService->updateSubTask($this->subTaskId, ['status' => TaskStatus::CANCELLED, 'summary' => 'Parent Task was Cancelled During the Task']);
5757
} catch (\Throwable $th) {
58-
$this->failTask($taskService, $th);
58+
$this->failSubTask($taskService, $th);
5959
throw $th;
6060
}
6161
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use LogicException;
1919
use 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];

app/Jobs/SyncFiles.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Illuminate\Support\Facades\Storage;
1212
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1313

14-
class SyncFiles extends ManagedTask {
14+
class SyncFiles extends ManagedSubTask {
1515
/**
1616
* Create a new job instance.
1717
*/
@@ -28,15 +28,15 @@ public function __construct($taskId) {
2828
* Execute the job.
2929
*/
3030
public function handle(TaskService $taskService): void {
31-
if (! $this->beginTask($taskService)) {
31+
if (! $this->beginSubTask($taskService)) {
3232
return;
3333
}
3434

3535
try {
3636
$this->syncCache($taskService);
37-
$this->completeTask($taskService);
37+
$this->completeSubTask($taskService);
3838
} catch (\Throwable $th) {
39-
$this->failTask($taskService, $th);
39+
$this->failSubTask($taskService, $th);
4040
throw $th;
4141
}
4242
}

app/Jobs/Utility/Paths/CleanFolderPaths.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
use App\Enums\TaskStatus;
66
use App\Exceptions\DataLostException;
7-
use App\Jobs\ManagedTask;
7+
use App\Jobs\ManagedSubTask;
88
use App\Models\Folder;
99
use App\Models\SubTask;
1010
use App\Services\TaskService;
1111
use Illuminate\Support\Facades\Storage;
1212

13-
class CleanFolderPaths extends ManagedTask {
13+
class CleanFolderPaths extends ManagedSubTask {
1414
/**
1515
* Create a new job instance.
1616
*/
@@ -25,15 +25,15 @@ public function __construct(public $folders, $taskId) {
2525
* Execute the job.
2626
*/
2727
public function handle(TaskService $taskService): void {
28-
if (! $this->beginTask($taskService)) {
28+
if (! $this->beginSubTask($taskService)) {
2929
return;
3030
}
3131

3232
try {
3333
$summary = $this->cleanFolderPaths($taskService);
34-
$this->completeTask($taskService, $summary);
34+
$this->completeSubTask($taskService, $summary);
3535
} catch (\Throwable $th) {
36-
$this->failTask($taskService, $th);
36+
$this->failSubTask($taskService, $th);
3737
throw $th;
3838
}
3939
}

app/Jobs/Utility/Paths/CleanVideoPaths.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
namespace App\Jobs\Utility\Paths;
44

55
use App\Enums\TaskStatus;
6-
use App\Jobs\ManagedTask;
6+
use App\Jobs\ManagedSubTask;
77
use App\Models\SubTask;
88
use App\Models\Video;
99
use App\Services\TaskService;
1010
use Illuminate\Support\Facades\Storage;
1111

12-
class CleanVideoPaths extends ManagedTask {
12+
class CleanVideoPaths extends ManagedSubTask {
1313
/**
1414
* Create a new job instance.
1515
*/
@@ -24,15 +24,15 @@ public function __construct(public $videos, $taskId) {
2424
* Execute the job.
2525
*/
2626
public function handle(TaskService $taskService): void {
27-
if (! $this->beginTask($taskService)) {
27+
if (! $this->beginSubTask($taskService)) {
2828
return;
2929
}
3030

3131
try {
3232
$summary = $this->cleanVideoPaths($taskService);
33-
$this->completeTask($taskService, $summary);
33+
$this->completeSubTask($taskService, $summary);
3434
} catch (\Throwable $th) {
35-
$this->failTask($taskService, $th);
35+
$this->failSubTask($taskService, $th);
3636
throw $th;
3737
}
3838
}

app/Jobs/VerifyFiles.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\Process\Exception\ProcessFailedException;
1919
use Symfony\Component\Process\Process;
2020

21-
class VerifyFiles extends ManagedTask {
21+
class VerifyFiles extends ManagedSubTask {
2222
/**
2323
* Execute the job.
2424
* id NOT_NULL -> INT8
@@ -55,23 +55,23 @@ public function __construct(public $videos, int $taskId) {
5555
}
5656

5757
public function handle(TaskService $taskService, SubtitleScanner $subtitleScanner): void {
58-
if (! $this->beginTask($taskService)) {
58+
if (! $this->beginSubTask($taskService)) {
5959
return;
6060
}
6161

6262
try {
6363
$summary = $this->verifyFiles($taskService, $subtitleScanner);
6464
$taskCountUpdates = count($this->embedChain) ? ['sub_tasks_complete' => '++', 'sub_tasks_total' => count($this->embedChain), 'sub_tasks_pending' => count($this->embedChain)] : ['sub_tasks_complete' => '++'];
6565

66-
$this->completeTask($taskService, $summary, $taskCountUpdates);
66+
$this->completeSubTask($taskService, $summary, $taskCountUpdates);
6767

6868
// Starts other subtasks after updating current subtask and parent subtask states
6969
// The parent task "ends" after the batch empties so in theory, this should delay that anyways and does not need to run before the task update
7070
foreach ($this->embedChain as $embedTask) {
7171
Bus::dispatch($embedTask);
7272
}
7373
} catch (\Throwable $th) {
74-
$this->failTask($taskService, $th);
74+
$this->failSubTask($taskService, $th);
7575
throw $th;
7676
}
7777
}

app/Jobs/VerifyFolders.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Illuminate\Support\Facades\Storage;
1414
use Illuminate\Support\Str;
1515

16-
class VerifyFolders extends ManagedTask {
16+
class VerifyFolders extends ManagedSubTask {
1717
/**
1818
* Create a new job instance.
1919
*/
@@ -27,15 +27,15 @@ public function __construct(public $folders, $taskId) {
2727
* Execute the job.
2828
*/
2929
public function handle(TaskService $taskService): void {
30-
if (! $this->beginTask($taskService)) {
30+
if (! $this->beginSubTask($taskService)) {
3131
return;
3232
}
3333

3434
try {
3535
$summary = $this->verifyFolders($taskService);
36-
$this->completeTask($taskService, $summary);
36+
$this->completeSubTask($taskService, $summary);
3737
} catch (\Throwable $th) {
38-
$this->failTask($taskService, $th);
38+
$this->failSubTask($taskService, $th);
3939
throw $th;
4040
}
4141
}

0 commit comments

Comments
 (0)