mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
feat: inspect device logs
feat: create DeviceLog model on log request feat: implement logs route, logs view feat: implement details on device log timezone, latest 50 log items sort by latest device timestamp cleanup job add tests
This commit is contained in:
parent
04d089c445
commit
c045dc1e85
12 changed files with 425 additions and 0 deletions
31
app/Jobs/CleanupDeviceLogsJob.php
Normal file
31
app/Jobs/CleanupDeviceLogsJob.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Device;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CleanupDeviceLogsJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
Device::each(function ($device) {
|
||||
$keepIds = $device->logs()->latest('device_timestamp')->take(50)->pluck('id');
|
||||
|
||||
// Delete all other logs for this device
|
||||
$device->logs()
|
||||
->whereNotIn('id', $keepIds)
|
||||
->delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue