After the first user registers, clears the setup token and dispatches NotifySetupCompleteJob to POST the token to MapleDeploy's callback URL. Adds setup_callback_url column to instance_settings.
55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
/**
|
|
* Notify MapleDeploy that the first user has registered on this Coolify instance.
|
|
*
|
|
* Sends the setup token as a Bearer token so MapleDeploy can verify authenticity
|
|
* and clear its stored copy. The token acts as a one-time shared secret.
|
|
*/
|
|
class NotifySetupCompleteJob implements ShouldBeEncrypted, ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public $tries = 5;
|
|
|
|
public array $backoff = [10, 30, 60, 120, 300];
|
|
|
|
public int $maxExceptions = 5;
|
|
|
|
public function __construct(
|
|
public string $setupToken,
|
|
public string $callbackUrl
|
|
) {
|
|
$this->onQueue('high');
|
|
}
|
|
|
|
public function handle(): void
|
|
{
|
|
$response = Http::withToken($this->setupToken)
|
|
->timeout(15)
|
|
->post($this->callbackUrl);
|
|
|
|
if (! $response->successful()) {
|
|
Log::warning('Setup-complete callback failed', [
|
|
'status' => $response->status(),
|
|
'url' => $this->callbackUrl,
|
|
]);
|
|
|
|
// Throw so the job retries
|
|
throw new \RuntimeException(
|
|
"Setup-complete callback returned HTTP {$response->status()}"
|
|
);
|
|
}
|
|
}
|
|
}
|