remove stale jobs

This commit is contained in:
2023-09-10 21:16:00 +10:00
parent d1cc468dfa
commit 4e7be1a18c
2 changed files with 41 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Console\Commands;
use App\Models\MediaJob;
use Illuminate\Console\Command;
class RemoveStaleMediaJobs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:remove-stale-media-jobs';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Remove media_jobs that have not been modified for 48 hours';
/**
* Execute the console command.
*/
public function handle()
{
$threshold = now()->subHours(48);
$staleJobs = MediaJob::where('updated_at', '<=', $threshold)->get();
foreach ($staleJobs as $job) {
$job->delete();
}
$this->info(count($staleJobs) . ' stale media_jobs removed.');
}
}

View File

@@ -15,7 +15,8 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
$schedule->command('app:cleanup-temp-files')->everySecond();
$schedule->command('app:cleanup-temp-files')->everyThirtyMinutes();
$schedule->command('app:remove-stale-media-jobs')->everyThirtyMinutes();
}
/**