Files
hermes c8c5822166
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 38s
[verified] Harden Etsy MCP validation and scheduled token refresh
2026-11-07 21:54:33 +00:00

57 lines
1.9 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Services\Bambuddy;
use App\Services\DryerClient;
use App\Services\Etsy;
use App\Services\IntegrationCache;
use App\Services\Parcel2Go;
use Closure;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
use Throwable;
#[Signature('integrations:refresh')]
#[Description('Refresh cached Etsy, Parcel2Go, BamBuddy and dryer data so dashboard pages load instantly')]
class RefreshIntegrationCache extends Command
{
public function handle(IntegrationCache $cache, Etsy $etsy, Parcel2Go $parcel2Go, Bambuddy $bambuddy, DryerClient $dryer): int
{
$cache->forceRefresh = true;
$this->refresh('parcel2go', function () use ($parcel2Go): void {
$parcel2Go->verifyCredentials();
foreach (['me/orders/detail', 'me/detail', 'me/prepay/balance'] as $path) {
$this->refresh('parcel2go '.$path, fn () => $parcel2Go->fetch($path));
}
});
if ($bambuddy->configured()) {
$this->refresh('bambuddy printers', fn () => $bambuddy->printers());
$this->refresh('bambuddy queue', fn () => $bambuddy->queue());
$this->refresh('bambuddy recent prints', fn () => $bambuddy->recentPrints());
$this->refresh('bambuddy stats', fn () => $bambuddy->stats());
$this->refresh('bambuddy spools', fn () => $bambuddy->spools());
}
if ($dryer->configured()) {
$this->refresh('dryer status', fn () => $dryer->status());
$this->refresh('dryer history', fn () => $dryer->history());
}
return self::SUCCESS;
}
private function refresh(string $label, Closure $fetch): void
{
try {
$fetch();
$this->line($label.': refreshed');
} catch (Throwable $exception) {
$this->warn($label.': '.$exception->getMessage());
}
}
}