Skip to content

Commit 2ce6ab2

Browse files
committed
fix: add update retry
1 parent 4761c10 commit 2ce6ab2

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

projects/app/src/pages/api/admin/inithalfvec.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
2727
}
2828

2929
let rowsUpdated;
30+
let retryCount = 0;
3031
do {
31-
rowsUpdated = await PgClient.query(`
32+
try {
33+
rowsUpdated = await PgClient.query(`
3234
WITH updated AS (
3335
UPDATE ${DatasetVectorTableName}
3436
SET halfvector = vector::halfvec(1536)
@@ -42,8 +44,22 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
4244
)
4345
SELECT count(*) FROM updated;
4446
`);
45-
console.log('rowsUpdated:', rowsUpdated.rows[0].count);
46-
} while (rowsUpdated.rows[0].count > 0);
47+
console.log('rowsUpdated:', rowsUpdated.rows[0].count);
48+
} catch (error) {
49+
console.error('Error updating halfvector:', error);
50+
retryCount++;
51+
}
52+
} while (retryCount < 3 && rowsUpdated!.rows[0].count > 0);
53+
54+
if (retryCount >= 3) {
55+
console.error('Failed to update halfvector after 3 retries');
56+
return jsonRes(res, {
57+
code: 500,
58+
error: 'Failed to update halfvector after 3 retries'
59+
});
60+
}
61+
62+
console.log('halfvector column updated');
4763

4864
// 设置halfvector字段为非空
4965
await PgClient.query(

0 commit comments

Comments
 (0)