remove stale jobs
This commit is contained in:
39
app/Console/Commands/RemoveStaleMediaJobs.php
Normal file
39
app/Console/Commands/RemoveStaleMediaJobs.php
Normal 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.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,8 @@ class Kernel extends ConsoleKernel
|
|||||||
protected function schedule(Schedule $schedule): void
|
protected function schedule(Schedule $schedule): void
|
||||||
{
|
{
|
||||||
// $schedule->command('inspire')->hourly();
|
// $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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user