-
Notifications
You must be signed in to change notification settings - Fork 338
Fix draining behaviour #1180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix draining behaviour #1180
Changes from all commits
4ee7ae9
6dce0f7
a1f2e91
48d8684
313665b
2fcf85d
69506b9
c848137
2cb243d
65b8e31
3fc9b65
3b1a7b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@livekit/agents": patch | ||
| --- | ||
|
|
||
| Fix worker draining behaviour |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| // SPDX-FileCopyrightText: 2024 LiveKit, Inc. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import type { Throws } from '@livekit/throws-transformer/throws'; | ||
| import type { RunningJobInfo } from '../job.js'; | ||
|
|
||
| export interface JobExecutor { | ||
|
|
@@ -9,11 +10,11 @@ export interface JobExecutor { | |
| runningJob: RunningJobInfo | undefined; | ||
| status: JobStatus; | ||
|
|
||
| start(): Promise<void>; | ||
| join(): Promise<void>; | ||
| initialize(): Promise<void>; | ||
| close(): Promise<void>; | ||
| launchJob(info: RunningJobInfo): Promise<void>; | ||
| start(): Promise<Throws<void, Error>>; | ||
| join(): Promise<Throws<void, Error>>; | ||
| initialize(): Promise<Throws<void, Error>>; | ||
| close(): Promise<Throws<void, Error>>; | ||
| launchJob(info: RunningJobInfo): Promise<Throws<void, Error>>; | ||
|
Comment on lines
+13
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can make a dedicated Error class for these operations?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, that would be nice, just didn't want to blow this PR out of scope |
||
| } | ||
|
|
||
| export enum JobStatus { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -837,7 +837,7 @@ export function waitUntilTimeout<T, E extends Error = IdleTimeoutError>( | |
| promise: Promise<T>, | ||
| timeoutMs: number, | ||
| throwError?: () => E, | ||
| ): Promise<Throws<T, E>> { | ||
| ): Promise<Throws<T, E | IdleTimeoutError>> { | ||
| let timer: ReturnType<typeof setTimeout> | undefined; | ||
| return Promise.race([ | ||
| promise, | ||
|
|
@@ -968,11 +968,20 @@ export async function waitForAbort(signal: AbortSignal) { | |
| abortFuture.resolve(); | ||
| signal.removeEventListener('abort', handler); | ||
| }; | ||
|
|
||
| if (signal.aborted) { | ||
| return; | ||
| } | ||
| signal.addEventListener('abort', handler, { once: true }); | ||
| return await abortFuture.await; | ||
| } | ||
|
|
||
| export async function rejectOnAbort(signal: AbortSignal): Promise<never> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we annotate this with Throws?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the annotation to be accurate we'd have to ensure that |
||
| if (signal.aborted) throw signal.reason; | ||
| const abortFuture = new Future<never>(); | ||
| signal.addEventListener('abort', () => abortFuture.reject(signal.reason), { once: true }); | ||
| return abortFuture.await; | ||
| } | ||
|
|
||
| /** | ||
| * Combines two abort signals into a single abort signal. | ||
| * @param a - The first abort signal. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.