feat(#17): add commands and jobs to poll, download and update firmware

feat(#17): add commands and jobs to poll, download and update firmware

feat(#17): update firmware modal

feat(#17): add tests
This commit is contained in:
Benjamin Nussbaum 2025-05-29 00:49:56 +02:00
parent 93aac51182
commit 87b9b57c3d
13 changed files with 567 additions and 3 deletions

View file

@ -0,0 +1,47 @@
<?php
namespace App\Jobs;
use App\Models\Firmware;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
class FirmwareDownloadJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private Firmware $firmware;
public function __construct(Firmware $firmware)
{
$this->firmware = $firmware;
}
public function handle(): void
{
if (! Storage::disk('public')->exists('firmwares')) {
Storage::disk('public')->makeDirectory('firmwares');
}
try {
$filename = "FW{$this->firmware->version_tag}.bin";
Http::sink(storage_path("app/public/firmwares/$filename"))
->get($this->firmware->url);
$this->firmware->update([
'storage_location' => "firmwares/$filename",
]);
} catch (ConnectionException $e) {
Log::error('Firmware download failed: '.$e->getMessage());
} catch (\Exception $e) {
Log::error('An unexpected error occurred: '.$e->getMessage());
}
}
}