fix requeue errors

This commit is contained in:
perf3ct 2025-03-28 20:37:09 +00:00
parent d201104662
commit 44cd2ebda6
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232

View File

@ -20,6 +20,7 @@ export async function queueNoteForEmbedding(noteId: string, operation = 'UPDATE'
const now = dateUtils.localNowDateTime();
const utcNow = dateUtils.utcNowDateTime();
try {
// Check if note is already in queue and whether it's marked as permanently failed
const queueInfo = await sql.getRow(
"SELECT 1 as exists_flag, failed, isProcessing FROM embedding_queue WHERE noteId = ?",
@ -55,6 +56,17 @@ export async function queueNoteForEmbedding(noteId: string, operation = 'UPDATE'
[noteId, operation, now, utcNow]
);
}
} catch (error: any) {
// If there's a race condition where multiple events try to queue the same note simultaneously,
// one of them will succeed and others will fail with UNIQUE constraint violation.
// We can safely ignore this specific error since the note is already queued.
if (error.code === 'SQLITE_CONSTRAINT_PRIMARYKEY' && error.message.includes('UNIQUE constraint failed: embedding_queue.noteId')) {
log.info(`Note ${noteId} was already queued by another process, ignoring duplicate queue request`);
return;
}
// Rethrow any other errors
throw error;
}
}
/**