Files
JeremyandClaude Opus 4.8 2be7a37c81 fix: address code review for per-product scheduling and notifications
- Product: reschedule next_check_at when refresh_interval changes; cast as int
- ScheduleHelper: bound FetchDue withoutOverlapping lock to 5 min
- PriceFetcherService: reschedule each chunk only after its job dispatches
- StockAlert mail: add alt text to product image
- AppSettings: mask Discord webhook URL (password + revealable)
- ListNotifications: scope mark-all-read to PriceBuddy notification types

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 11:20:23 +10:00

58 lines
2.0 KiB
PHP

<?php
namespace App\Services\Helpers;
use App\Console\Commands\FetchAll;
use App\Console\Commands\FetchDue;
use App\Models\UrlResearch;
use Illuminate\Console\Scheduling\Schedule;
use Lorisleiva\CronTranslator\CronTranslator;
use Throwable;
use Yoeriboven\LaravelLogDb\Models\LogMessage;
class ScheduleHelper
{
/**
* Invalid cron expression text.
*/
public static function getInvalidCronText(): string
{
return __('Invalid cron expression');
}
/**
* Parse cron expression and return a human-readable string or huma-readable invalid text.
*/
public static function parseCronExpression(?string $expression): string
{
try {
return CronTranslator::translate($expression, CurrencyHelper::getLocale());
} catch (Throwable $e) {
return self::getInvalidCronText();
}
}
/**
* Register the scheduled commands for the application. Abstracted for testing.
*/
public static function registerSchedule(Schedule $schedule): void
{
// Check for new prices on the global schedule (products without a custom interval)
$schedule->command(FetchAll::COMMAND, ['--log'])
->cron(SettingsHelper::getSetting('scrape_schedule', '0 6 * * *'));
// Check for new prices on products with a custom interval that are due
$schedule->command(FetchDue::COMMAND, ['--log'])
->everyMinute()
// The command only enqueues jobs, so it finishes in seconds. Cap the
// lock so a crashed/unclean run can't block the next minute for the
// 24h default.
->withoutOverlapping(5);
// Prune old log messages
$schedule->command('model:prune', ['--model' => [LogMessage::class]])->daily();
// Prune search research results.
$schedule->command('model:prune', ['--model' => [UrlResearch::class]])->daily();
// Prune expired Sanctum tokens
$schedule->command('sanctum:prune-expired', ['--hours' => 24])->daily();
}
}