Respect Reddit rate limit delays
This commit is contained in:
1 parent
7bcdbe236a
commit
50de1c180d
5 files changed
+77
-10
No files matched your search
+8
-1
@@ -3,6 +3,7 @@ import { withRetry } from './utils/retry.js';
|
||||
import { isSkip } from './services/processor.js';
|
||||
import { reportDeliveryResult, reportInvitationCooldown } from './web/event-reporting.js';
|
||||
import { SessionBoundRuntime } from './services/session-bound-runtime.js';
|
||||
import { RedditRateLimitError } from './reddit/api.js';
|
||||
|
||||
export interface StoppableSchedule {
|
||||
stop(): void;
|
||||
@@ -395,7 +396,13 @@ export async function runMainLoop(app: AppContainer): Promise<void> {
|
||||
}
|
||||
} catch (error) {
|
||||
if (isShuttingDown && error instanceof DOMException && error.name === 'AbortError') break;
|
||||
logger.error('Error in main loop:', error);
|
||||
if (error instanceof RedditRateLimitError) {
|
||||
await sleep(Math.max(ERROR_BACKOFF_MS, error.retryAfterMs + 1_000), shutdownController.signal);
|
||||
continue;
|
||||
}
|
||||
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
logger.error(`Error in main loop: ${errorMessage}`);
|
||||
await sleep(ERROR_BACKOFF_MS, shutdownController.signal);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user