Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\EtsyConnection;
|
|
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;
|
|
|
|
if (($connection = EtsyConnection::first()) && $etsy->configured()) {
|
|
$this->refresh('etsy receipts', fn () => $etsy->receipts($connection));
|
|
$this->refresh('etsy listings', fn () => $etsy->listings($connection));
|
|
}
|
|
|
|
$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());
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|