mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
33 lines
909 B
PHP
33 lines
909 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
/**
|
|
* Stores the host that created the execution, so a host can count only the runs of its own workers.
|
|
* The host name is internal, so API and MCP responses do not show it.
|
|
*/
|
|
trait RecordsWorkerHost
|
|
{
|
|
protected static function bootRecordsWorkerHost(): void
|
|
{
|
|
static::creating(function (self $execution): void {
|
|
$execution->worker_host ??= gethostname();
|
|
});
|
|
}
|
|
|
|
protected function initializeRecordsWorkerHost(): void
|
|
{
|
|
$this->hidden[] = 'worker_host';
|
|
}
|
|
|
|
/**
|
|
* Rows without a host were created before the column existed, so they can belong to this host.
|
|
*/
|
|
public function scopeOnThisHost(Builder $query): Builder
|
|
{
|
|
return $query->where(fn (Builder $query) => $query->where('worker_host', gethostname())->orWhereNull('worker_host'));
|
|
}
|
|
}
|