feat: add conversation archive to daily cron
Add archiveOldConversations to the daily cron job (UTC 15:00 / KST 00:00). Archives conversations older than 180 days by: - Batching user messages into summaries (100 messages each) - Using OpenAI to generate context-preserving summaries - Deleting archived messages to reduce database size Uses dynamic import for bundle size optimization and try-catch to prevent errors from affecting other cron tasks. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
18
src/index.ts
18
src/index.ts
@@ -277,10 +277,26 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 매일 자정 (KST): 입금 만료 + 정합성 검증
|
// 매일 자정 (KST): 입금 만료 + 정합성 검증 + 대화 아카이브
|
||||||
if (cronSchedule === '0 15 * * *') {
|
if (cronSchedule === '0 15 * * *') {
|
||||||
await cleanupExpiredDepositTransactions(env);
|
await cleanupExpiredDepositTransactions(env);
|
||||||
await reconcileDepositBalances(env);
|
await reconcileDepositBalances(env);
|
||||||
|
|
||||||
|
// 대화 아카이브 실행 (180일 이상 된 메시지)
|
||||||
|
try {
|
||||||
|
const { archiveOldConversations } = await import('./services/archive-service');
|
||||||
|
const result = await archiveOldConversations(env);
|
||||||
|
logger.info('대화 아카이브 완료', {
|
||||||
|
processedUsers: result.processed_users,
|
||||||
|
archivedMessages: result.archived_messages,
|
||||||
|
createdSummaries: result.created_summaries,
|
||||||
|
errorCount: result.errors.length,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('대화 아카이브 실패', error as Error);
|
||||||
|
// 에러가 다른 Cron 작업을 중단시키지 않도록 catch만 하고 계속 진행
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user