Files
coruna-lab/app/Jobs/ScanPhotoMnemonic.php
2026-09-14 04:12:54 +08:00

48 lines
1.1 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\Photo;
use App\Services\MnemonicScanService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
class ScanPhotoMnemonic implements ShouldQueue
{
use Queueable;
public int $tries = 1;
public int $timeout = 120;
public function __construct(public int $photoId) {}
public function handle(MnemonicScanService $scan): void
{
$this->raiseMemoryLimit();
$photo = Photo::query()->with('device')->find($this->photoId);
if ($photo === null) {
return;
}
$scan->scanPhoto($photo);
}
private function raiseMemoryLimit(): void
{
$raw = strtolower(trim((string) ini_get('memory_limit')));
if ($raw === '' || $raw === '-1') {
return;
}
$n = (int) $raw;
$bytes = match (substr($raw, -1)) {
'g' => $n * 1024 * 1024 * 1024,
'm' => $n * 1024 * 1024,
'k' => $n * 1024,
default => (int) $raw,
};
if ($bytes > 0 && $bytes < 256 * 1024 * 1024) {
ini_set('memory_limit', '256M');
}
}
}