Skip to main content

BackgroundStatus

The return type of controller.backgroundStatus() from initLatestDeployment(). Provides health information about the background polling loop that keeps a deployment up to date.

Definition

interface BackgroundStatus {
  stopped: boolean;
  consecutiveFailures: number;
  lastError: Error | null;
  lastRefreshed: Date;
}

Fields

FieldTypeDescription
stoppedbooleantrue if the background polling loop has been stopped (either manually via controller.stop() or due to unrecoverable errors).
consecutiveFailuresnumberThe number of consecutive refresh failures since the last successful poll. Resets to 0 on a successful refresh.
lastErrorError | nullThe most recent error encountered during polling, or null if the last refresh succeeded.
lastRefreshedDateTimestamp of the last successful deployment refresh.

Usage

import { Adaline } from '@adaline/client';

const adaline = new Adaline();

const { deployment, controller } = await adaline.initLatestDeployment({
  promptId: 'prompt_abc123',
  deploymentEnvironmentId: 'environment_abc123',
});

// Check the health of background polling
const status = controller.backgroundStatus();

console.log(`Stopped: ${status.stopped}`);
console.log(`Consecutive failures: ${status.consecutiveFailures}`);
console.log(`Last error: ${status.lastError?.message ?? 'none'}`);
console.log(`Last refreshed: ${status.lastRefreshed.toISOString()}`);

Health monitoring

Use backgroundStatus() in a periodic health check to detect degraded state:
setInterval(() => {
  const status = controller.backgroundStatus();

  if (status.stopped) {
    console.error('Background refresh stopped — deployments are stale');
  } else if (status.consecutiveFailures > 3) {
    console.warn(
      `Deployment refresh degraded: ${status.consecutiveFailures} consecutive failures. ` +
      `Last error: ${status.lastError?.message}`
    );
  }
}, 30_000);

See Also

  • AdalineinitLatestDeployment() returns the controller that exposes this type