coolify/app/Models/GithubRunnerConfig.php
Andras Bacsai 1739c04d32
Some checks are pending
Staging Build / build-push (aarch64, linux/aarch64, ubuntu-24.04-arm) (push) Waiting to run
Staging Build / build-push (amd64, linux/amd64, ubuntu-24.04) (push) Waiting to run
Staging Build / merge-manifest (push) Blocked by required conditions
feat(github-runners): add capacity wait timeout and deferred repo loading
Add configurable `capacity_wait_timeout` to runner configs and use it in
`ProvisionGithubRunnerJob` to re-dispatch jobs while at capacity, preserving
initial wait start time and stopping after timeout.

Improve runner provisioning by caching an extracted runner template and copying
it into new runner directories.

Update Livewire GitHub Runners UI to lazy-load accessible repositories via
`wire:init`, track loading state, add timeout input, and remove preinstall
binary action.

Add/extend feature tests for capacity retry timeout behavior and deferred
repository loading.
2026-03-03 18:37:10 +01:00

64 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class GithubRunnerConfig extends BaseModel
{
protected $guarded = [];
protected function casts(): array
{
return [
'labels' => 'array',
'is_enabled' => 'boolean',
'max_runners' => 'integer',
'capacity_wait_timeout' => 'integer',
];
}
public function organization(): Attribute
{
return Attribute::make(
get: fn () => $this->githubApp?->organization,
);
}
public function server(): BelongsTo
{
return $this->belongsTo(Server::class);
}
public function githubApp(): BelongsTo
{
return $this->belongsTo(GithubApp::class);
}
public function executions(): HasMany
{
return $this->hasMany(GithubRunnerExecution::class);
}
public function activeRunnerCount(): int
{
return $this->executions()
->whereIn('status', ['queued', 'provisioning', 'running', 'cleaning'])
->count();
}
public function hasCapacity(): bool
{
return $this->activeRunnerCount() < $this->max_runners;
}
public function matchesLabels(array $requestedLabels): bool
{
$configLabels = collect($this->labels)->map(fn ($l) => strtolower($l));
return collect($requestedLabels)
->every(fn ($label) => $configLabels->contains(strtolower($label)));
}
}