mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix: provide waitUntil to Gateway listener so it stays alive
The startGatewayListener returns immediately without waitUntil because it's designed for serverless. In standalone mode we need to provide a waitUntil function that tracks background tasks and wait for them.
This commit is contained in:
@@ -56,12 +56,24 @@ async function main() {
|
||||
const runGateway = async () => {
|
||||
while (true) {
|
||||
try {
|
||||
await discord.startGatewayListener(
|
||||
{},
|
||||
// Track background tasks so the listener stays alive
|
||||
const pendingTasks: Promise<unknown>[] = [];
|
||||
const waitUntil = (task: Promise<unknown>) => {
|
||||
pendingTasks.push(task);
|
||||
};
|
||||
|
||||
const response = await discord.startGatewayListener(
|
||||
{ waitUntil },
|
||||
10 * 60 * 1000, // 10 minutes
|
||||
undefined,
|
||||
webhookUrl
|
||||
);
|
||||
|
||||
// Wait for any background tasks to complete
|
||||
if (pendingTasks.length > 0) {
|
||||
await Promise.allSettled(pendingTasks);
|
||||
}
|
||||
|
||||
console.log("[gateway] Listener ended, restarting...");
|
||||
} catch (err) {
|
||||
console.error("[gateway] Error, restarting in 5s:", err);
|
||||
|
||||
Reference in New Issue
Block a user