Add settings-driven Artisan scheduler registry with Etsy sync and token refresh jobs
Introduces App\Support\DashboardSchedule (modelled on LHITS_Dashboard's pattern) as a single settings-driven registry for recurring Artisan jobs, replacing the two hard-coded Schedule::command() lines in routes/console.php. Migrated unchanged: - integrations_refresh (integrations:refresh), every_30_seconds, withoutOverlapping(5) - alerts_scan (alerts:scan), every_30_seconds, withoutOverlapping(5) New: - etsy_sync (etsy:sync), every_15_minutes - forces a fresh pull of Etsy receipts/listings into the existing IntegrationCache entries, decoupled from the bundled integrations:refresh job so it can be tuned/disabled independently of Parcel2Go/BamBuddy/dryer refreshes. - etsy_token_refresh (etsy:refresh-token), every_45_minutes - proactively refreshes the Etsy OAuth token (tokens last ~1hr) via a new public Etsy::refreshAccessToken() wrapper around the existing on-demand accessToken() refresh logic, so the connection survives quiet periods. Frequency is persisted to storage/app/dashboard-schedules.json (no app_settings table exists in this app, unlike LHITS's AppSetting-backed store) and surfaced in a new 'Scheduler' section on the existing Settings page (ScheduleSettingsController + routes), with per-job frequency dropdowns and manual 'Run now' buttons, matching the page's existing Tailwind conventions. Tests: SchedulerTest (registry/frequency behavior), ScheduleSettingsTest (settings UI + authorization), EtsySyncScheduledJobsTest (new commands, Http::fake only, no live Etsy calls).
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\EtsyConnection;
|
||||
use App\Services\Etsy;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
use Throwable;
|
||||
|
||||
#[Signature('etsy:refresh-token')]
|
||||
#[Description('Proactively refresh the Etsy OAuth access token so the connection survives quiet periods')]
|
||||
class EtsyRefreshToken extends Command
|
||||
{
|
||||
public function handle(Etsy $etsy): int
|
||||
{
|
||||
$connection = EtsyConnection::first();
|
||||
|
||||
if (! $connection || ! $etsy->configured()) {
|
||||
$this->line('Etsy token refresh skipped: shop is not configured or not connected.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
try {
|
||||
$etsy->refreshAccessToken($connection);
|
||||
$this->line('etsy token: refreshed, expires at '.$connection->refresh()->expires_at->toIso8601String());
|
||||
} catch (Throwable $exception) {
|
||||
$this->warn('etsy token: '.$exception->getMessage());
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\EtsyConnection;
|
||||
use App\Services\Etsy;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
use Throwable;
|
||||
|
||||
#[Signature('etsy:sync')]
|
||||
#[Description('Force a fresh pull of Etsy receipts and active listings into the dashboard cache')]
|
||||
class EtsySync extends Command
|
||||
{
|
||||
public function handle(Etsy $etsy): int
|
||||
{
|
||||
$connection = EtsyConnection::first();
|
||||
|
||||
if (! $connection || ! $etsy->configured()) {
|
||||
$this->line('Etsy sync skipped: shop is not configured or not connected.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
try {
|
||||
$receipts = $etsy->receipts($connection, fresh: true);
|
||||
$this->line('etsy receipts: refreshed ('.($receipts['count'] ?? 0).' open)');
|
||||
} catch (Throwable $exception) {
|
||||
$this->warn('etsy receipts: '.$exception->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
$listings = $etsy->listings($connection, fresh: true);
|
||||
$this->line('etsy listings: refreshed ('.count($listings['results'] ?? []).' active)');
|
||||
} catch (Throwable $exception) {
|
||||
$this->warn('etsy listings: '.$exception->getMessage());
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user