22 lines
627 B
PHP
22 lines
627 B
PHP
<?php
|
|
|
|
namespace Modules\Analytics\Console;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Modules\Analytics\Models\AnalyticsReport;
|
|
|
|
final class RunScheduledReports extends Command
|
|
{
|
|
protected $signature = 'analytics:reports';
|
|
|
|
protected $description = 'Queue analytics reports that are due.';
|
|
|
|
public function handle(): int
|
|
{
|
|
$count = AnalyticsReport::where('is_active', true)->whereNotNull('next_run_at')->where('next_run_at', '<=', now())->update(['last_run_at' => now(), 'next_run_at' => now()->addDay()]);
|
|
$this->info("Processed {$count} scheduled reports.");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|