@livekit/agents 1.0.0-next.4 → 1.0.0-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/worker.ts CHANGED
@@ -61,7 +61,7 @@ class Default {
61
61
  }
62
62
  }
63
63
 
64
- /** Necessary credentials not provided and not found in an appropriate environmental variable. */
64
+ /** Necessary credentials not provided and not found in an appropriate environment variable. */
65
65
  export class MissingCredentialsError extends Error {
66
66
  constructor(msg?: string) {
67
67
  super(msg);
@@ -82,7 +82,9 @@ export const defaultInitializeProcessFunc = (_: JobProcess) => _;
82
82
  const defaultRequestFunc = async (ctx: JobRequest) => {
83
83
  await ctx.accept();
84
84
  };
85
- const defaultCpuLoad = async (): Promise<number> => {
85
+
86
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
87
+ const defaultCpuLoad = async (worker: Worker): Promise<number> => {
86
88
  return new Promise((resolve) => {
87
89
  const cpus1 = os.cpus();
88
90
 
@@ -147,7 +149,7 @@ export class WorkerPermissions {
147
149
  export class WorkerOptions {
148
150
  agent: string;
149
151
  requestFunc: (job: JobRequest) => Promise<void>;
150
- loadFunc: () => Promise<number>;
152
+ loadFunc: (worker: Worker) => Promise<number>;
151
153
  loadThreshold: number;
152
154
  numIdleProcesses: number;
153
155
  shutdownProcessTimeout: number;
@@ -198,7 +200,7 @@ export class WorkerOptions {
198
200
  agent: string;
199
201
  requestFunc?: (job: JobRequest) => Promise<void>;
200
202
  /** Called to determine the current load of the worker. Should return a value between 0 and 1. */
201
- loadFunc?: () => Promise<number>;
203
+ loadFunc?: (worker: Worker) => Promise<number>;
202
204
  /** When the load exceeds this threshold, the worker will be marked as unavailable. */
203
205
  loadThreshold?: number;
204
206
  numIdleProcesses?: number;
@@ -437,7 +439,7 @@ export class Worker {
437
439
  return;
438
440
  }
439
441
 
440
- this.#logger.info('draining worker');
442
+ this.#logger.debug('draining worker');
441
443
  this.#draining = true;
442
444
 
443
445
  this.event.emit(
@@ -616,7 +618,7 @@ export class Worker {
616
618
  if (closingWS) clearInterval(loadMonitor);
617
619
 
618
620
  const oldStatus = currentStatus;
619
- this.#opts.loadFunc().then((currentLoad: number) => {
621
+ this.#opts.loadFunc(this).then((currentLoad: number) => {
620
622
  const isFull = currentLoad >= this.#opts.loadThreshold;
621
623
  const currentlyAvailable = !isFull;
622
624
  currentStatus = currentlyAvailable ? WorkerStatus.WS_AVAILABLE : WorkerStatus.WS_FULL;
@@ -753,7 +755,7 @@ export class Worker {
753
755
  return;
754
756
  }
755
757
 
756
- this.#logger.info('shutting down worker');
758
+ this.#logger.debug('shutting down worker');
757
759
 
758
760
  this.#closed = true;
759
761