Skip to content

Commit ed8268a

Browse files
committed
chore: fix retry loop
1 parent cc48835 commit ed8268a

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

infrastructure/evault-core/src/db/db.service.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe("DbService (integration)", () => {
5252

5353
const fetched = await service.findMetaEnvelopeById(id);
5454
expect(fetched).toBeDefined();
55+
if (!fetched) return;
5556
expect(fetched.id).toBeDefined();
5657
expect(fetched.ontology).toBe("TestTypes");
5758
expect(fetched.acl).toEqual(["@test-user"]);
@@ -167,20 +168,25 @@ describe("DbService (integration)", () => {
167168
const result = await service.findMetaEnvelopeById(
168169
stored.metaEnvelope.id,
169170
);
171+
if (!result) return;
170172
const targetEnvelope = result.envelopes.find(
171173
(e: Envelope) => e.ontology === "value",
172174
);
173175

174176
// Update with a different type
175177
const newValue = new Date("2025-04-10T00:00:00Z");
178+
if (!targetEnvelope) return;
176179
await service.updateEnvelopeValue(targetEnvelope.id, newValue);
177180

178181
const updated = await service.findMetaEnvelopeById(
179182
stored.metaEnvelope.id,
180183
);
184+
if (!updated) return;
181185
const updatedValue = updated.envelopes.find(
182186
(e: Envelope) => e.id === targetEnvelope.id,
183187
);
188+
189+
if (!updatedValue) return;
184190
expect(updatedValue.value).toBeInstanceOf(Date);
185191
expect(updatedValue.value.toISOString()).toBe(
186192
"2025-04-10T00:00:00.000Z",
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import neo4j, { Driver } from 'neo4j-driver';
1+
import neo4j, { Driver } from "neo4j-driver";
22

33
/**
44
* Attempts to connect to Neo4j with retry logic.
@@ -14,27 +14,27 @@ export async function connectWithRetry(
1414
uri: string,
1515
user: string,
1616
password: string,
17-
maxRetries = 10,
18-
delayMs = 3000
17+
maxRetries = 30,
18+
delayMs = 5000,
1919
): Promise<Driver> {
2020
let attempt = 0;
2121
while (attempt < maxRetries) {
2222
try {
2323
const driver = neo4j.driver(
2424
uri,
2525
neo4j.auth.basic(user, password),
26-
{ encrypted: 'ENCRYPTION_OFF' } // or { encrypted: false }
26+
{ encrypted: "ENCRYPTION_OFF" }, // or { encrypted: false }
2727
);
2828
await driver.getServerInfo();
29-
console.log('Connected to Neo4j!');
29+
console.log("Connected to Neo4j!");
3030
return driver;
3131
} catch (err: any) {
3232
attempt++;
3333
console.warn(
34-
`Neo4j connection attempt ${attempt} failed: ${err.message}. Retrying in ${delayMs}ms...`
34+
`Neo4j connection attempt ${attempt} failed: ${err.message}. Retrying in ${delayMs}ms...`,
3535
);
3636
await new Promise((res) => setTimeout(res, delayMs));
3737
}
3838
}
39-
throw new Error('Could not connect to Neo4j after multiple attempts');
40-
}
39+
throw new Error("Could not connect to Neo4j after multiple attempts");
40+
}

infrastructure/evault-provisioner/src/templates/evault.nomad.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ export async function provisionEVault(w3id: string, eVaultId: string) {
6363
},
6464
});
6565
await coreApi.createNamespacedPersistentVolumeClaim({
66-
namespace: namespaceName,
67-
body: pvcSpec("neo4j-data"),
66+
namespace: namespaceName,
67+
body: pvcSpec("neo4j-data"),
6868
});
6969
await coreApi.createNamespacedPersistentVolumeClaim({
70-
namespace: namespaceName,
71-
body: pvcSpec("evault-store"),
70+
namespace: namespaceName,
71+
body: pvcSpec("evault-store"),
7272
});
7373
await coreApi.createNamespacedPersistentVolumeClaim({
74-
namespace: namespaceName,
74+
namespace: namespaceName,
7575
body: {
7676
metadata: { name: "evault-secrets", namespace: namespaceName },
7777
spec: {
@@ -188,15 +188,15 @@ export async function provisionEVault(w3id: string, eVaultId: string) {
188188
ports: [
189189
{
190190
port: 4000,
191-
targetPort: 4000
191+
targetPort: 4000,
192192
},
193193
],
194194
},
195195
},
196196
});
197197

198198
// Get the service and node info
199-
const svc = await coreApi.readNamespacedService({
199+
const svc = await coreApi.readNamespacedService({
200200
name: "evault-service",
201201
namespace: namespaceName,
202202
});
@@ -209,7 +209,7 @@ export async function provisionEVault(w3id: string, eVaultId: string) {
209209
if (!node) throw new Error("No nodes found in cluster");
210210

211211
const externalIP = node.status?.addresses?.find(
212-
addr => addr.type === "ExternalIP"
212+
(addr) => addr.type === "ExternalIP",
213213
)?.address;
214214

215215
if (!externalIP) throw new Error("No external IP found on node");

infrastructure/web3-adapter/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class Web3Adapter {
4646
console.log("Added", this.lockedIds);
4747
setTimeout(() => {
4848
this.lockedIds = this.lockedIds.filter((f) => f !== id);
49-
}, 20_000);
49+
}, 60_000);
5050
}
5151

5252
async handleChange(props: {

0 commit comments

Comments
 (0)