From 6ce3ecdbd57832472e66874ec7e585f8b0c31cf7 Mon Sep 17 00:00:00 2001 From: Leslie Wong <79917148leslie@gmail.com> Date: Tue, 25 Apr 2023 21:33:08 +0800 Subject: [PATCH] Recursion to ensure that collection exists --- loader.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/loader.js b/loader.js index e7c6911..806f059 100644 --- a/loader.js +++ b/loader.js @@ -57,11 +57,21 @@ const initializeMilvusCollection = async () => { ], }; - await milvusClient.collectionManager.releaseCollection({ collection_name: "shotit" }); - - await milvusClient.collectionManager.createCollection(params); + const fallBack = async () => { + try { + await milvusClient.collectionManager.releaseCollection({ collection_name: "shotit" }); + await milvusClient.collectionManager.createCollection(params); + console.log('collection_name: "shotit" ensured'); + milvusClient.closeConnection(); + } catch (error) { + console.log(error); + console.log("initializeMilvusCollection reconnecting in 3 seconds"); + await new Promise((resolve) => setTimeout(resolve, 1000 * 3)); + await fallBack(); + } + }; - milvusClient.closeConnection(); + await fallBack(); }; /**