Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/Http/Controllers/Admin/Maintenance/FullTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Http\Resources\Diagnostics\AlbumTree;
use Illuminate\Routing\Controller;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

/**
* Maybe the album tree is broken.
Expand All @@ -28,9 +29,12 @@ class FullTree extends Controller
*/
public function do(FullTreeUpdateRequest $request): void
{
$key_name = 'id';
$album_instance = new Album();
batch()->update($album_instance, $request->albums(), $key_name);
// Wrap this in a transaction to ensure atomicity
DB::transaction(function () use ($request): void {
$key_name = 'id';
$album_instance = new Album();
batch()->update($album_instance, $request->albums(), $key_name);
});

AlbumRouteCacheUpdated::dispatch();
}
Expand Down
2 changes: 2 additions & 0 deletions app/Jobs/ExtractColoursJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;

/**
Expand Down Expand Up @@ -62,6 +63,7 @@ public function __construct(
*/
public function handle(): Photo
{
Log::channel('jobs')->info("Starting colour extraction job for photo ID {$this->photo_id}.");
$this->history->status = JobStatus::STARTED;
$this->history->save();

Expand Down
5 changes: 3 additions & 2 deletions app/Jobs/ExtractZip.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function __construct(
*/
public function handle(): void
{
Log::channel('jobs')->info("Starting extraction job for file {$this->original_base_name}.");
$this->history->status = JobStatus::STARTED;
$this->history->save();

Expand Down Expand Up @@ -130,7 +131,7 @@ public function handle(): void
// @codeCoverageIgnoreStart
} catch (\Throwable $e) {
// Fail silently if dispatched sync.
Log::error(__LINE__ . ':' . __FILE__ . ' ' . $e->getMessage(), $e->getTrace());
Log::channel('jobs')->error(__LINE__ . ':' . __FILE__ . ' ' . $e->getMessage(), $e->getTrace());
}
// @codeCoverageIgnoreEnd
}
Expand Down Expand Up @@ -192,7 +193,7 @@ private function validate_zip(): void
$zip->close();

if (count($unsafe_entries) > 0) {
Log::critical('Zip file ' . $this->file_path . ' contains unsafe entries.', $unsafe_entries);
Log::channel('jobs')->critical('Zip file ' . $this->file_path . ' contains unsafe entries.', $unsafe_entries);

$this->history->status = JobStatus::FAILURE;
$this->history->save();
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/HasFailedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function failed(\Throwable $th): void
if ($th->getCode() === 999) {
$this->release();
} else {
Log::error(__LINE__ . ':' . __FILE__ . ' ' . $th->getMessage(), $th->getTrace());
Log::channel('jobs')->error(__LINE__ . ':' . __FILE__ . ' ' . $th->getMessage(), $th->getTrace());
}
}
}
2 changes: 2 additions & 0 deletions app/Jobs/ImportImageJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;

/**
Expand Down Expand Up @@ -67,6 +68,7 @@ public function __construct(
*/
public function handle(AlbumFactory $album_factory): Photo
{
Log::channel('jobs')->info($this->history->job);
$this->history->status = JobStatus::STARTED;
$this->history->save();

Expand Down
2 changes: 2 additions & 0 deletions app/Jobs/ProcessImageJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;

/**
Expand Down Expand Up @@ -102,6 +103,7 @@ public function handle(AlbumFactory $album_factory): Photo
{
$this->history->status = JobStatus::STARTED;
$this->history->save();
Log::channel('jobs')->info($this->history->job);

$copied_file = new TemporaryJobFile($this->file_path, $this->original_base_name);

Expand Down
12 changes: 6 additions & 6 deletions app/Jobs/RecomputeAlbumSizeJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function hasNewerJobQueued(): bool
// We skip if there is a newer job queued (latest job ID is different from this one)
$has_newer_job = $latest_job_id !== null && $latest_job_id !== $this->jobId;
if ($has_newer_job) {
Log::info("Skipping job {$this->jobId} for album {$this->album_id} due to newer job {$latest_job_id} queued.");
Log::channel('jobs')->debug("Skipping job {$this->jobId} for album {$this->album_id} due to newer job {$latest_job_id} queued.");
}

return $has_newer_job;
Expand All @@ -95,7 +95,7 @@ protected function hasNewerJobQueued(): bool
*/
public function handle(): void
{
Log::info("Recomputing sizes for album {$this->album_id} (job {$this->jobId})");
Log::channel('jobs')->info("Recomputing sizes for album {$this->album_id} (job {$this->jobId})");
Cache::forget("album_size_latest_job:{$this->album_id}");

try {
Expand All @@ -117,15 +117,15 @@ public function handle(): void
$sizes
);

Log::debug("Updated size statistics for album {$album->id}");
Log::channel('jobs')->debug("Updated size statistics for album {$album->id}");

// Propagate to parent if exists
if ($album->parent_id !== null && $this->propagate_to_parent) {
Log::debug("Propagating to parent {$album->parent_id}");
Log::channel('jobs')->debug("Propagating to parent {$album->parent_id}");
self::dispatch($album->parent_id);
}
} catch (\Exception $e) {
Log::error("Propagation stopped at album {$this->album_id} due to failure: " . $e->getMessage());
Log::channel('jobs')->error("Propagation stopped at album {$this->album_id} due to failure: " . $e->getMessage());

throw $e;
}
Expand Down Expand Up @@ -188,7 +188,7 @@ private function computeSizes(Album $album): array
*/
public function failed(\Throwable $exception): void
{
Log::error("Job failed permanently for album {$this->album_id}: " . $exception->getMessage());
Log::channel('jobs')->error("Job failed permanently for album {$this->album_id}: " . $exception->getMessage());
// Do NOT dispatch parent job on failure - propagation stops here
}
}
16 changes: 8 additions & 8 deletions app/Jobs/RecomputeAlbumStatsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function hasNewerJobQueued(): bool
// We skip if there is no newer job, or if the latest job is not this one
$has_newer_job = $latest_job_id !== null && $latest_job_id !== $this->jobId;
if ($has_newer_job) {
Log::info("Skipping job {$this->jobId} for album {$this->album_id} due to newer job {$latest_job_id} queued.");
Log::channel('jobs')->debug("Skipping job {$this->jobId} for album {$this->album_id} due to newer job {$latest_job_id} queued.");
}

return $has_newer_job;
Expand All @@ -100,13 +100,13 @@ protected function hasNewerJobQueued(): bool
*/
public function handle(): void
{
Log::info("Recomputing stats for album {$this->album_id}");
Log::channel('jobs')->info("Recomputing stats for album {$this->album_id}");
Cache::forget("album_stats_latest_job:{$this->album_id}");

// This is a safety check to avoid recomputing albums
// when no admin user exists.
if (DB::table('users')->where('may_administrate', '=', true)->count() === 0) {
Log::error("No admin user exists, skipping recompute for album {$this->album_id}.");
Log::channel('jobs')->critical("No admin user exists, skipping recompute for album {$this->album_id}.");

return;
}
Expand All @@ -115,7 +115,7 @@ public function handle(): void
// Fetch the album.
$album = Album::where('id', '=', $this->album_id)->first();
if ($album === null) {
Log::warning("Album {$this->album_id} not found, skipping recompute.");
Log::channel('jobs')->warning("Album {$this->album_id} not found, skipping recompute.");

return;
}
Expand All @@ -139,16 +139,16 @@ public function handle(): void
// Compute cover IDs (simplified for now - will be enhanced in I3)
$album->auto_cover_id_max_privilege = $this->computeMaxPrivilegeCover($album, $is_nsfw_context);
$album->auto_cover_id_least_privilege = $this->computeLeastPrivilegeCover($album, $is_nsfw_context);
Log::debug("Computed covers for album {$album->id}: max_privilege=" . ($album->auto_cover_id_max_privilege ?? 'null') . ', least_privilege=' . ($album->auto_cover_id_least_privilege ?? 'null'));
Log::channel('jobs')->debug("Computed covers for album {$album->id}: max_privilege=" . ($album->auto_cover_id_max_privilege ?? 'null') . ', least_privilege=' . ($album->auto_cover_id_least_privilege ?? 'null'));
$album->save();

// Propagate to parent if exists
if ($album->parent_id !== null && $this->propagate_to_parent) {
Log::debug("Propagating to parent {$album->parent_id}");
Log::channel('jobs')->debug("Propagating to parent {$album->parent_id}");
self::dispatch($album->parent_id);
}
} catch (\Exception $e) {
Log::error("Propagation stopped at album {$this->album_id} due to failure: " . $e->getMessage());
Log::channel('jobs')->error("Propagation stopped at album {$this->album_id} due to failure: " . $e->getMessage());

throw $e;
}
Expand Down Expand Up @@ -359,7 +359,7 @@ private function computeLeastPrivilegeCover(Album $album, bool $is_nsfw_context)
*/
public function failed(\Throwable $exception): void
{
Log::error("Job failed permanently for album {$this->album_id}: " . $exception->getMessage());
Log::channel('jobs')->error("Job failed permanently for album {$this->album_id}: " . $exception->getMessage());
// Do NOT dispatch parent job on failure - propagation stops here
}
}
4 changes: 2 additions & 2 deletions app/Jobs/UploadSizeVariantToS3Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function failed(\Throwable $th): void
if ($th->getCode() === 999) {
$this->release();
} else {
Log::error(__LINE__ . ':' . __FILE__ . ' Upload failed for ' . $this->variant->short_path);
Log::error(__LINE__ . ':' . __FILE__ . ' ' . $th->getMessage(), $th->getTrace());
Log::channel('jobs')->error(__LINE__ . ':' . __FILE__ . ' Upload failed for ' . $this->variant->short_path);
Log::channel('jobs')->error(__LINE__ . ':' . __FILE__ . ' ' . $th->getMessage(), $th->getTrace());
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/WatermarkerJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function failed(\Throwable $th): void
if ($th->getCode() === 999) {
$this->release();
} else {
Log::error(__LINE__ . ':' . __FILE__ . ' Watermark failed for ' . $this->variant->short_path,
Log::channel('jobs')->error(__LINE__ . ':' . __FILE__ . ' Watermark failed for ' . $this->variant->short_path,
[
'variant_id' => $this->variant->id,
'path' => $this->variant->short_path,
Expand Down
9 changes: 5 additions & 4 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use App\Policies\SettingsPolicy;
use App\Repositories\ConfigManager;
use App\Services\MoneyService;
use Illuminate\Database\Connection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Http\Resources\Json\JsonResource;
Expand Down Expand Up @@ -257,7 +258,7 @@ private function registerLoggerAccess(): void
/**
* @codeCoverageIgnore
*/
private function logSQLStart(string $sql, array $bindings, string $connection): void
private function logSQLStart(string $sql, array $bindings, Connection $connection): void
{
$uri = request()?->getRequestUri() ?? '';
// Quick exit
Expand Down Expand Up @@ -289,7 +290,7 @@ private function logSQLStart(string $sql, array $bindings, string $connection):
$msg = 'START: ' . $sql . ' [' . implode(', ', $bindings) . ']';

$context = [
'connection' => $connection,
'connection' => $connection->getDriverName(),
'url' => request()?->fullUrl() ?? 'N/A',
];

Expand Down Expand Up @@ -326,7 +327,7 @@ private function logSQL(QueryExecuted $query): void
config('database.explain', false) === false ||
!Str::contains($query->sql, 'select')
) {
Log::debug($msg);
Log::warning($msg);

return;
}
Expand All @@ -350,7 +351,7 @@ private function logSQL(QueryExecuted $query): void
$msg .= Str::repeat('-', 20) . PHP_EOL;
$msg .= $sql_with_bindings . PHP_EOL;
$msg .= $renderer->getTable($explain);
Log::debug($msg);
Log::warning($msg);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,22 @@
'path' => storage_path('logs/deprecations.log'),
'level' => 'debug',
],

// Specific channel for job logs (e.g., to debug queue issues)
'jobs' => [
'driver' => 'stack',
'channels' => [
'jobs-daily',
'error',
'warning',
],
],

// Specific channel for job logs (e.g., to debug queue issues)
'jobs-daily' => [
'driver' => 'daily',
'path' => storage_path('logs/jobs.log'),
'level' => 'debug',
],
],
];
Loading