aboutsummaryrefslogtreecommitdiffstats
path: root/lib/db.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-12-27 23:22:27 -0800
committerAdam Soltys <[email protected]>2023-12-28 22:51:02 -0800
commit02a373b8128c1544711d14ecd6ed19e20c7e3b0b (patch)
tree51327752718eac827273ada093fe6060d7184f56 /lib/db.js
parentaaf8dd49b07066e534408a2d41d84c518a45c2b6 (diff)
downloadcoinos-server-02a373b8128c1544711d14ecd6ed19e20c7e3b0b.tar.gz
coinos-server-02a373b8128c1544711d14ecd6ed19e20c7e3b0b.zip
liquid wip
Diffstat (limited to 'lib/db.js')
-rw-r--r--lib/db.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/db.js b/lib/db.js
index d14e4962..c44c7177 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -41,16 +41,33 @@ export let db = createClient({
},
});
-async function connectWithRetry() {
+export let archive = createClient({
+ url: config.archive,
+ socket: {
+ reconnectStrategy: (retries) => Math.min(retries * 50, 5000),
+ },
+});
+
+async function dbReconnect() {
try {
await db.connect();
} catch (err) {
console.error("Failed to connect to Redis, retrying...", err);
- setTimeout(connectWithRetry, 5000); // Retry after 5 seconds
+ setTimeout(dbReconnect, 5000); // Retry after 5 seconds
+ }
+}
+
+async function archiveReconnect() {
+ try {
+ await archive.connect();
+ } catch (err) {
+ console.error("Failed to connect to Redis, retrying...", err);
+ setTimeout(archiveReconnect, 5000); // Retry after 5 seconds
}
}
-connectWithRetry();
+dbReconnect();
+archiveReconnect();
db.on("error", (e) => {
if (e.message.startsWith("getaddr")) return;