refactor: abstract identify throttling and correct max_concurrency handling (#9375)

* refactor: properly support max_concurrency ratelimit keys

* fix: properly block for same key

* chore: export session state

* chore: throttler no longer requires manager

* refactor: abstract throttlers

* chore: proper member order

* chore: remove leftover debug log

* chore: use @link tag in doc comment

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* chore: suggested changes

* fix(WebSocketShard): cancel identify if the shard closed in the meantime

* refactor(throttlers): support abort signals

* fix: memory leak

* chore: remove leftover

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
DD
2023-04-14 23:26:37 +03:00
committed by GitHub
parent cac3c07729
commit 02dfaf1aa2
16 changed files with 279 additions and 161 deletions

View File

@@ -117,7 +117,7 @@ export class WorkerBootstrapper {
break;
}
case WorkerSendPayloadOp.ShardCanIdentify: {
case WorkerSendPayloadOp.ShardIdentifyResponse: {
break;
}
@@ -127,11 +127,11 @@ export class WorkerBootstrapper {
throw new Error(`Shard ${payload.shardId} does not exist`);
}
const response = {
const response: WorkerReceivePayload = {
op: WorkerReceivePayloadOp.FetchStatusResponse,
status: shard.status,
nonce: payload.nonce,
} satisfies WorkerReceivePayload;
};
parentPort!.postMessage(response);
break;
@@ -150,12 +150,12 @@ export class WorkerBootstrapper {
for (const event of options.forwardEvents ?? Object.values(WebSocketShardEvents)) {
// @ts-expect-error: Event types incompatible
shard.on(event, (data) => {
const payload = {
const payload: WorkerReceivePayload = {
op: WorkerReceivePayloadOp.Event,
event,
data,
shardId,
} satisfies WorkerReceivePayload;
};
parentPort!.postMessage(payload);
});
}
@@ -168,9 +168,9 @@ export class WorkerBootstrapper {
// Lastly, start listening to messages from the parent thread
this.setupThreadEvents();
const message = {
const message: WorkerReceivePayload = {
op: WorkerReceivePayloadOp.WorkerReady,
} satisfies WorkerReceivePayload;
};
parentPort!.postMessage(message);
}
}