mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
- 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>
58 lines
2.0 KiB
PHP
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();
|
|
}
|
|
}
|