PlatformQueueDrainService
in package
Drains the default and active-tenant Queue plugin datasources fairly.
Table of Contents
Constants
- DEFAULT_CYCLE_BUDGET_SECONDS : mixed = 240
- MAX_CYCLE_BUDGET_SECONDS : mixed = 300
Properties
- $clock : Closure
- $defaultDatasourceIdentity : string|null
- $platformConnection : Connection|null
- $queueDrainService : QueueDrainService
- $tenantConnectionManager : TenantConnectionManager
- $wallClock : Closure
Methods
- __construct() : mixed
-
drain()
: array{default: int, tenants: array
, failures: array , duplicateTenants: list , deferredTenants: list , datasourcesProcessed: int, jobsProcessed: int, elapsedMs: float} - activeTenants() : array<int, TenantMetadata>
- connection() : Connection
- datasourceIdentity() : string
- Normalize a physical PostgreSQL datasource identity.
- remainingRuntime() : int|null
- Return a bounded datasource runtime, or null after the fleet deadline.
- resolvedDefaultDatasourceIdentity() : string
- Resolve the normalized host/database identity for the default datasource.
- rotatedTenants() : array<int, TenantMetadata>
- runtimeForRemainingBudget() : int
- Return the runtime available to the default datasource.
- tenantDatasourceIdentity() : string
- Resolve the normalized host/database identity for a tenant datasource.
Constants
DEFAULT_CYCLE_BUDGET_SECONDS
public
mixed
DEFAULT_CYCLE_BUDGET_SECONDS
= 240
MAX_CYCLE_BUDGET_SECONDS
public
mixed
MAX_CYCLE_BUDGET_SECONDS
= 300
Properties
$clock read-only
private
Closure
$clock
$defaultDatasourceIdentity read-only
private
string|null
$defaultDatasourceIdentity
= null
$platformConnection read-only
private
Connection|null
$platformConnection
= null
$queueDrainService read-only
private
QueueDrainService
$queueDrainService
$tenantConnectionManager read-only
private
TenantConnectionManager
$tenantConnectionManager
$wallClock read-only
private
Closure
$wallClock
Methods
__construct()
public
__construct(QueueDrainService $queueDrainService, TenantConnectionManager $tenantConnectionManager[, Connection|null $platformConnection = null ][, string|null $defaultDatasourceIdentity = null ][, Closure|null $clock = null ][, Closure|null $wallClock = null ]) : mixed
Parameters
- $queueDrainService : QueueDrainService
-
Queue processor
- $tenantConnectionManager : TenantConnectionManager
-
Tenant connection binder
- $platformConnection : Connection|null = null
-
Optional platform connection override
- $defaultDatasourceIdentity : string|null = null
-
Optional physical default datasource identity
- $clock : Closure|null = null
-
Optional monotonic clock returning seconds
- $wallClock : Closure|null = null
-
Optional wall clock returning Unix seconds
drain()
public
drain([int $maxJobs = QueueDrainService::MAX_JOBS ][, int $maxRuntimeSeconds = QueueDrainService::DEFAULT_MAX_RUNTIME_SECONDS ][, int $cycleBudgetSeconds = self::DEFAULT_CYCLE_BUDGET_SECONDS ]) : array{default: int, tenants: array, failures: array, duplicateTenants: list, deferredTenants: list, datasourcesProcessed: int, jobsProcessed: int, elapsedMs: float}
Parameters
- $maxJobs : int = QueueDrainService::MAX_JOBS
- $maxRuntimeSeconds : int = QueueDrainService::DEFAULT_MAX_RUNTIME_SECONDS
- $cycleBudgetSeconds : int = self::DEFAULT_CYCLE_BUDGET_SECONDS
Return values
array{default: int, tenants: arrayactiveTenants()
private
activeTenants() : array<int, TenantMetadata>
Return values
array<int, TenantMetadata>connection()
private
connection() : Connection
Return values
ConnectiondatasourceIdentity()
Normalize a physical PostgreSQL datasource identity.
private
datasourceIdentity(string $host, string $database) : string
Parameters
- $host : string
- $database : string
Return values
stringremainingRuntime()
Return a bounded datasource runtime, or null after the fleet deadline.
private
remainingRuntime(int $maxRuntimeSeconds, float $deadline) : int|null
Parameters
- $maxRuntimeSeconds : int
- $deadline : float
Return values
int|nullresolvedDefaultDatasourceIdentity()
Resolve the normalized host/database identity for the default datasource.
private
resolvedDefaultDatasourceIdentity() : string
Return values
stringrotatedTenants()
private
rotatedTenants(array<int, TenantMetadata> $tenants, float $startedAt) : array<int, TenantMetadata>
Parameters
- $tenants : array<int, TenantMetadata>
- $startedAt : float
Return values
array<int, TenantMetadata>runtimeForRemainingBudget()
Return the runtime available to the default datasource.
private
runtimeForRemainingBudget(int $maxRuntimeSeconds, float $deadline) : int
Parameters
- $maxRuntimeSeconds : int
- $deadline : float
Return values
inttenantDatasourceIdentity()
Resolve the normalized host/database identity for a tenant datasource.
private
tenantDatasourceIdentity(TenantMetadata $tenant) : string
Parameters
- $tenant : TenantMetadata