A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
fix task ended
aminnausin9d69254efa17
diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.phpindex c36b30a4..7e4adb77 100755--- a/app/Http/Controllers/DirectoryController.php+++ b/app/Http/Controllers/DirectoryController.php@@ -412,19 +412,17 @@ class DirectoryController extends Controller {$duration = 0;}- $this->taskService->updateTask($task->id, [- 'status' => $status,- // 'sub_tasks_pending' => $batch->pendingJobs,- // 'sub_tasks_failed' => $batch->failedJobs,- // 'sub_tasks_complete' => $task->sub_tasks_total - $batch->pendingJobs - $batch->failedJobs,- 'ended_at' => $ended_at,- 'duration' => $duration < 0 ? $duration * -1 : $duration,- ]);-try {- broadcast(new TaskEnded($task));+ $this->taskService->updateTask($task->id, [+ 'status' => $status,+ // 'sub_tasks_pending' => $batch->pendingJobs,+ // 'sub_tasks_failed' => $batch->failedJobs,+ // 'sub_tasks_complete' => $task->sub_tasks_total - $batch->pendingJobs - $batch->failedJobs,+ 'ended_at' => $ended_at,+ 'duration' => $duration < 0 ? $duration * -1 : $duration,+ ], $status === TaskStatus::COMPLETED);} catch (\Throwable $th) {- Log::error('Unable to broadcast task ended', $th->getMessage());+ Log::error('Error when completing task', $th->getMessage());}})->before(function (Batch $batch) use ($task) {$this->taskService->updateTask($task->id, [diff --git a/app/Jobs/EmbedUidInMetadata.php b/app/Jobs/EmbedUidInMetadata.phpindex b186d043..b5713994 100644--- a/app/Jobs/EmbedUidInMetadata.php+++ b/app/Jobs/EmbedUidInMetadata.php@@ -110,7 +110,7 @@ class EmbedUidInMetadata implements ShouldQueue {'status' => $status,'ended_at' => $ended_at,'duration' => $duration < 0 ? $duration * -1 : $duration,- ]);+ ], $status === TaskStatus::COMPLETED);} catch (\Throwable $th) {$endedAt = now();$duration = (int) $this->startedAt->diffInSeconds($endedAt);diff --git a/app/Services/TaskService.php b/app/Services/TaskService.phpindex e2f0591b..beb6e95c 100644--- a/app/Services/TaskService.php+++ b/app/Services/TaskService.php@@ -3,6 +3,7 @@namespace App\Services;use App\Events\SubTaskUpdated;+use App\Events\TaskEnded;use App\Events\TaskUpdated;use App\Models\SubTask;use App\Models\Task;@@ -31,7 +32,7 @@ class TaskService {/*** Update Task by ID.*/- public function updateTask(int $taskId, array $attr): ?Task {+ public function updateTask(int $taskId, array $attr, bool $taskEnded = false): ?Task {$task = Task::find($taskId);if (! $task) {@@ -44,7 +45,11 @@ class TaskService {$task->save();try {- broadcast(new TaskUpdated($task));+ if ($taskEnded) {+ broadcast(new TaskEnded($task));+ } else {+ broadcast(new TaskUpdated($task));+ }} catch (\Throwable $th) {dump($th->getMessage());Log::error('Unable to broadcast task update', ['error' => $th->getMessage()]);