Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Repository;
|
|
use App\Services\Git\GitException;
|
|
use App\Services\Git\GitManager;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class SyncRepository implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public int $tries = 3;
|
|
|
|
/**
|
|
* Spread retries out: the usual cause of failure is a rate limit, and
|
|
* retrying immediately just burns the remaining allowance.
|
|
*
|
|
* @var array<int, int>
|
|
*/
|
|
public array $backoff = [60, 600];
|
|
|
|
public function __construct(public Repository $repository) {}
|
|
|
|
/**
|
|
* @return array<int, object>
|
|
*/
|
|
public function middleware(): array
|
|
{
|
|
// A manual "sync now" and the hourly schedule can easily coincide.
|
|
return [(new WithoutOverlapping((string) $this->repository->id))->dontRelease()];
|
|
}
|
|
|
|
public function handle(GitManager $git): void
|
|
{
|
|
try {
|
|
$git->sync($this->repository);
|
|
} catch (GitException $e) {
|
|
Log::warning('Repository sync failed', [
|
|
'repository' => $this->repository->full_name,
|
|
'provider' => $this->repository->provider->value,
|
|
'message' => $e->getMessage(),
|
|
]);
|
|
|
|
// A deleted or renamed repository will never succeed, so stop
|
|
// retrying. The failure is already recorded on the model and shown
|
|
// in the panel.
|
|
if (! $e->isTransient) {
|
|
$this->fail($e);
|
|
|
|
return;
|
|
}
|
|
|
|
throw $e;
|
|
}
|
|
}
|
|
}
|