AppFolio API 속도 제한
개요
AppFolio API는 파트너별로 속도 제한을 적용합니다. 제한 내에서 유지하기 위해 스로틀링을 구현하세요.
속도 제한 처리기
import Bottleneck from "bottleneck";
const limiter = new Bottleneck({
maxConcurrent: 5,
minTime: 200, // 초당 최대 5개 요청
});
async function throttledRequest(client: any, path: string) {
return limiter.schedule(() => client.http.get(path));
}
// 429 재시도
async function withRetry(fn: () => Promise<any>, maxRetries = 3) {
for (let i = 1; i <= maxRetries; i++) {
try { return await fn(); }
catch (err: any) {
if (err.response?.status !== 429 || i === maxRetries) throw err;
const delay = Math.min(1000 * Math.pow(2, i), 30000);
await new Promise(r => setTimeout(r, delay));
}
}
}