Cache integration API reads and refresh them on a schedule
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Hickmeister
2026-10-11 19:01:32 +01:00
co-authored by Claude Sonnet 5.5
parent 8bee8d42c7
commit 2fe4fbd91e
10 changed files with 253 additions and 24 deletions
@@ -0,0 +1,58 @@
<?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());
}
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());
}
}
}