Zum Hauptinhalt springen

AdapterPoolMemberDrainExitService

Namespace: Meshmakers.Octo.Sdk.Common.Adapters

Stops a pool member's process once it is draining and idle, so the pool workload restarts it as a fresh, clean process (AB#5864).

public sealed class AdapterPoolMemberDrainExitService : BackgroundService, IHostedService, IDisposable

Inheritance Object → BackgroundService → AdapterPoolMemberDrainExitService
Implements IHostedService, IDisposable

Remarks:

The drain contract always said "it finishes what it holds, takes no further lease and exits" (ILeaseService.DrainMemberAsync in the controller, concept §6) — and no member ever exited. A drained member sat 1/1 Running for the rest of its life: on test-2-dev a lease participant that failed to leave drained the only member of a pool, and every later execution of every borrower failed until somebody deleted the pod.

Exiting is the recovery, not a punishment. A member drains because its cleanliness is unproven (a participant failed to leave, its lease expired server-side) or because the pool is giving it up; in neither case can the process be made trustworthy again from the inside. A container restart can: the new process starts with no tenant state at all, registers as available, and the controller's registry drops the old registration as superseded (same member id, new connection).

🔴 It waits for AdapterPoolClient.IsDrainedAndIdle, never only for the drain flag. A drain that arrives during a lease lets the lease finish; stopping earlier would lose the release report, and the controller would then interrupt and re-run work that had already completed.

Stopping the host is a graceful shutdown — the management connection is closed cleanly by AdapterPoolMemberService.StopAsync(CancellationToken), which the controller sees as a disconnect of a member that holds no lease, so nothing is re-queued. Disabled with AdapterPool:ExitWhenDrained=false (AdapterPoolMemberOptions.ExitWhenDrained); the member then only drops out of readiness and stays until something else restarts it.

Properties​

ExecuteTask​

public Task ExecuteTask { get; }

Property Value​

Task

Constructors​

AdapterPoolMemberDrainExitService(AdapterPoolClient, IOptions<AdapterPoolMemberOptions>, AdapterLifetimeManagement)​

Constructor.

public AdapterPoolMemberDrainExitService(AdapterPoolClient poolClient, IOptions<AdapterPoolMemberOptions> options, AdapterLifetimeManagement lifetimeManagement)

Parameters​

poolClient AdapterPoolClient
The member's half of the lease protocol, which knows whether it drains.

options IOptions<AdapterPoolMemberOptions>
The pool member configuration (AdapterPoolMemberOptions.ExitWhenDrained).

lifetimeManagement AdapterLifetimeManagement
Stops the host.

Methods​

ExecuteAsync(CancellationToken)​

protected Task ExecuteAsync(CancellationToken stoppingToken)

Parameters​

stoppingToken CancellationToken

Returns​

Task

Evaluate()​

One sample: stops the host when the member is drained and idle and reports whether it did. Internal so the decision can be tested without the timer.

internal bool Evaluate()

Returns​

Boolean