Skip to content

A self-hosted media server and file management system

fix: managed task is a managed subtask and should be named as such

aminnausinacd7ec5cc5c7
diff --git a/app/Jobs/EmbedUidInMetadata.php b/app/Jobs/EmbedUidInMetadata.php
index 956ce975..4901b41a 100644
--- a/app/Jobs/EmbedUidInMetadata.php
+++ b/app/Jobs/EmbedUidInMetadata.php
@@ -12,7 +12,7 @@ use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
#[DeleteWhenMissingModels]
-class EmbedUidInMetadata extends ManagedTask {
+class EmbedUidInMetadata extends ManagedSubTask {
protected $filePath;
protected $uuid;
@@ -41,11 +41,11 @@ class EmbedUidInMetadata extends ManagedTask {
* Execute the job.
*/
public function handle(TaskService $taskService): void {
- $this->beginTask($taskService, "Adding uuid to $this->filePath");
+ $this->beginSubTask($taskService, "Adding uuid to $this->filePath");
try {
$summary = $this->handleEmbed();
- $task = $this->completeTask($taskService, $summary);
+ $task = $this->completeSubTask($taskService, $summary);
if ($this->videoId) {
Video::where('id', $this->videoId)->update(['uuid' => $this->uuid]);
@@ -74,7 +74,7 @@ class EmbedUidInMetadata extends ManagedTask {
], $status === TaskStatus::COMPLETED);
} catch (\Throwable $th) {
dump($th->getMessage());
- $this->failTask($taskService, $th);
+ $this->failSubTask($taskService, $th);
if ($this->batch()) {
// Batch error handling is in the job service
throw $th;
diff --git a/app/Jobs/GeneratePreviewImage.php b/app/Jobs/GeneratePreviewImage.php
index a2f63c72..68f48fff 100644
--- a/app/Jobs/GeneratePreviewImage.php
+++ b/app/Jobs/GeneratePreviewImage.php
@@ -8,7 +8,7 @@ use App\Services\GenerateImageException;
use App\Services\PreviewGeneratorService;
use App\Services\TaskService;
-class GeneratePreviewImage extends ManagedTask {
+class GeneratePreviewImage extends ManagedSubTask {
protected $itemTitle;
public $timeout = 3600;
@@ -32,7 +32,7 @@ class GeneratePreviewImage extends ManagedTask {
}
public function handle(PreviewGeneratorService $previewGenerator, TaskService $taskService) {
- if (! $this->beginTask($taskService)) {
+ if (! $this->beginSubTask($taskService)) {
return;
}
@@ -41,9 +41,9 @@ class GeneratePreviewImage extends ManagedTask {
if (! $result) {
throw new GenerateImageException('Preview image generation failed. View logs for error.');
}
- $this->completeTask($taskService, 'Generated preview image.');
+ $this->completeSubTask($taskService, 'Generated preview image.');
} catch (\Throwable $th) {
- $this->failTask($taskService, $th);
+ $this->failSubTask($taskService, $th);
throw $th;
}
}
diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.php
index c0eab6a6..379e2276 100755
--- a/app/Jobs/IndexFiles.php
+++ b/app/Jobs/IndexFiles.php
@@ -16,7 +16,7 @@ use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Ramsey\Uuid\Uuid;
-class IndexFiles extends ManagedTask {
+class IndexFiles extends ManagedSubTask {
protected $taskService;
protected $embedChain = [];
@@ -39,7 +39,7 @@ class IndexFiles extends ManagedTask {
*/
public function handle(TaskService $taskService): void {
$this->taskService = $taskService; // Only for this job for compatibility since this will be re-written soon
- $this->beginTask($taskService, 'Starting Index Files');
+ $this->beginSubTask($taskService, 'Starting Index Files');
dump('Starting Index Files');
@@ -47,7 +47,7 @@ class IndexFiles extends ManagedTask {
$summary = $this->generateData();
$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' => '++'];
- $this->completeTask($taskService, $summary, $taskCountUpdates);
+ $this->completeSubTask($taskService, $summary, $taskCountUpdates);
foreach ($this->embedChain as $embedTask) {
$this->batch()->add($embedTask);
@@ -55,7 +55,7 @@ class IndexFiles extends ManagedTask {
} catch (BatchCancelledException $e) {
$taskService->updateSubTask($this->subTaskId, ['status' => TaskStatus::CANCELLED, 'summary' => 'Parent Task was Cancelled During the Task']);
} catch (\Throwable $th) {
- $this->failTask($taskService, $th);
+ $this->failSubTask($taskService, $th);
throw $th;
}
}
diff --git a/app/Jobs/ManagedTask.php b/app/Jobs/ManagedSubTask.php
similarity index 87%
rename from app/Jobs/ManagedTask.php
rename to app/Jobs/ManagedSubTask.php
index d4c90621..f829e71b 100644
--- a/app/Jobs/ManagedTask.php
+++ b/app/Jobs/ManagedSubTask.php
@@ -18,7 +18,7 @@ use Illuminate\Support\Facades\DB;
use LogicException;
use Throwable;
-abstract class ManagedTask implements ShouldQueue {
+abstract class ManagedSubTask implements ShouldQueue {
use Batchable, Dispatchable, EnsuresTaskIsStarted, HasUpsert, InteractsWithQueue, Queueable, SerializesModels;
protected int $taskId;
@@ -35,7 +35,7 @@ abstract class ManagedTask implements ShouldQueue {
* Sets subtask to processing
* Sets subtask starting summary
*/
- public function beginTask(TaskService $taskService, string $summary = ''): bool {
+ public function beginSubTask(TaskService $taskService, string $summary = ''): bool {
if (! $this->taskId) {
throw new LogicException('Task ID missing, cannot begin task');
}
@@ -63,7 +63,7 @@ abstract class ManagedTask implements ShouldQueue {
return true;
}
- public function completeTask(TaskService $taskService, string $summary = '', array $taskCountUpdates = ['sub_tasks_complete' => '++']): ?Task {
+ public function completeSubTask(TaskService $taskService, string $summary = '', array $taskCountUpdates = ['sub_tasks_complete' => '++']): ?Task {
$shouldBroadcastTaskUpdate = array_key_exists('sub_tasks_total', $taskCountUpdates);
$endedAt = now();
@@ -77,6 +77,8 @@ abstract class ManagedTask implements ShouldQueue {
'duration' => $duration,
];
+ // TODO: This forces 100% completed state but this value should be calculated wait nevermind this is a subtask
+
DB::transaction(function () use ($taskService, $taskCountUpdates, $shouldBroadcastTaskUpdate, $subTaskUpdates) {
$taskService->updateTaskCounts($this->taskId, $taskCountUpdates, $shouldBroadcastTaskUpdate); // TODO: Move broadcasts outside of updates?
$taskService->updateSubTask($this->subTaskId, $subTaskUpdates);
@@ -85,7 +87,7 @@ abstract class ManagedTask implements ShouldQueue {
return Task::find($this->taskId);
}
- public function failTask(TaskService $taskService, Throwable $th): void {
+ public function failSubTask(TaskService $taskService, Throwable $th): void {
$endedAt = now();
$duration = $this->getTaskDuration($endedAt);
$subTaskUpdates = ['status' => TaskStatus::FAILED, 'summary' => 'Error: ' . $th->getMessage(), 'ended_at' => $endedAt, 'duration' => $duration];
diff --git a/app/Jobs/SyncFiles.php b/app/Jobs/SyncFiles.php
index 507a8987..3ba15d88 100755
--- a/app/Jobs/SyncFiles.php
+++ b/app/Jobs/SyncFiles.php
@@ -11,7 +11,7 @@ use App\Services\TaskService;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-class SyncFiles extends ManagedTask {
+class SyncFiles extends ManagedSubTask {
/**
* Create a new job instance.
*/
@@ -28,15 +28,15 @@ class SyncFiles extends ManagedTask {
* Execute the job.
*/
public function handle(TaskService $taskService): void {
- if (! $this->beginTask($taskService)) {
+ if (! $this->beginSubTask($taskService)) {
return;
}
try {
$this->syncCache($taskService);
- $this->completeTask($taskService);
+ $this->completeSubTask($taskService);
} catch (\Throwable $th) {
- $this->failTask($taskService, $th);
+ $this->failSubTask($taskService, $th);
throw $th;
}
}
diff --git a/app/Jobs/Utility/Paths/CleanFolderPaths.php b/app/Jobs/Utility/Paths/CleanFolderPaths.php
index 2ac114e8..1c529d6e 100644
--- a/app/Jobs/Utility/Paths/CleanFolderPaths.php
+++ b/app/Jobs/Utility/Paths/CleanFolderPaths.php
@@ -4,13 +4,13 @@ namespace App\Jobs\Utility\Paths;
use App\Enums\TaskStatus;
use App\Exceptions\DataLostException;
-use App\Jobs\ManagedTask;
+use App\Jobs\ManagedSubTask;
use App\Models\Folder;
use App\Models\SubTask;
use App\Services\TaskService;
use Illuminate\Support\Facades\Storage;
-class CleanFolderPaths extends ManagedTask {
+class CleanFolderPaths extends ManagedSubTask {
/**
* Create a new job instance.
*/
@@ -25,15 +25,15 @@ class CleanFolderPaths extends ManagedTask {
* Execute the job.
*/
public function handle(TaskService $taskService): void {
- if (! $this->beginTask($taskService)) {
+ if (! $this->beginSubTask($taskService)) {
return;
}
try {
$summary = $this->cleanFolderPaths($taskService);
- $this->completeTask($taskService, $summary);
+ $this->completeSubTask($taskService, $summary);
} catch (\Throwable $th) {
- $this->failTask($taskService, $th);
+ $this->failSubTask($taskService, $th);
throw $th;
}
}
diff --git a/app/Jobs/Utility/Paths/CleanVideoPaths.php b/app/Jobs/Utility/Paths/CleanVideoPaths.php
index 3156c213..b9f80409 100644
--- a/app/Jobs/Utility/Paths/CleanVideoPaths.php
+++ b/app/Jobs/Utility/Paths/CleanVideoPaths.php
@@ -3,13 +3,13 @@
namespace App\Jobs\Utility\Paths;
use App\Enums\TaskStatus;
-use App\Jobs\ManagedTask;
+use App\Jobs\ManagedSubTask;
use App\Models\SubTask;
use App\Models\Video;
use App\Services\TaskService;
use Illuminate\Support\Facades\Storage;
-class CleanVideoPaths extends ManagedTask {
+class CleanVideoPaths extends ManagedSubTask {
/**
* Create a new job instance.
*/
@@ -24,15 +24,15 @@ class CleanVideoPaths extends ManagedTask {
* Execute the job.
*/
public function handle(TaskService $taskService): void {
- if (! $this->beginTask($taskService)) {
+ if (! $this->beginSubTask($taskService)) {
return;
}
try {
$summary = $this->cleanVideoPaths($taskService);
- $this->completeTask($taskService, $summary);
+ $this->completeSubTask($taskService, $summary);
} catch (\Throwable $th) {
- $this->failTask($taskService, $th);
+ $this->failSubTask($taskService, $th);
throw $th;
}
}
diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.php
index 245cb567..3d22b0fd 100755
--- a/app/Jobs/VerifyFiles.php
+++ b/app/Jobs/VerifyFiles.php
@@ -18,7 +18,7 @@ use Ramsey\Uuid\Uuid;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
-class VerifyFiles extends ManagedTask {
+class VerifyFiles extends ManagedSubTask {
/**
* Execute the job.
* id NOT_NULL -> INT8
@@ -55,7 +55,7 @@ class VerifyFiles extends ManagedTask {
}
public function handle(TaskService $taskService, SubtitleScanner $subtitleScanner): void {
- if (! $this->beginTask($taskService)) {
+ if (! $this->beginSubTask($taskService)) {
return;
}
@@ -63,7 +63,7 @@ class VerifyFiles extends ManagedTask {
$summary = $this->verifyFiles($taskService, $subtitleScanner);
$taskCountUpdates = count($this->embedChain) ? ['sub_tasks_complete' => '++', 'sub_tasks_total' => count($this->embedChain), 'sub_tasks_pending' => count($this->embedChain)] : ['sub_tasks_complete' => '++'];
- $this->completeTask($taskService, $summary, $taskCountUpdates);
+ $this->completeSubTask($taskService, $summary, $taskCountUpdates);
// Starts other subtasks after updating current subtask and parent subtask states
// 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
@@ -71,7 +71,7 @@ class VerifyFiles extends ManagedTask {
Bus::dispatch($embedTask);
}
} catch (\Throwable $th) {
- $this->failTask($taskService, $th);
+ $this->failSubTask($taskService, $th);
throw $th;
}
}
diff --git a/app/Jobs/VerifyFolders.php b/app/Jobs/VerifyFolders.php
index 1c2a22ae..1377fa05 100644
--- a/app/Jobs/VerifyFolders.php
+++ b/app/Jobs/VerifyFolders.php
@@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
-class VerifyFolders extends ManagedTask {
+class VerifyFolders extends ManagedSubTask {
/**
* Create a new job instance.
*/
@@ -27,15 +27,15 @@ class VerifyFolders extends ManagedTask {
* Execute the job.
*/
public function handle(TaskService $taskService): void {
- if (! $this->beginTask($taskService)) {
+ if (! $this->beginSubTask($taskService)) {
return;
}
try {
$summary = $this->verifyFolders($taskService);
- $this->completeTask($taskService, $summary);
+ $this->completeSubTask($taskService, $summary);
} catch (\Throwable $th) {
- $this->failTask($taskService, $th);
+ $this->failSubTask($taskService, $th);
throw $th;
}
}