Open gchicoye opened 1 year ago
Hey, any news on that? Thanks!
Hi, would it be possible to get some insight on this? Thanks!
Hi @gchicoye, do you have some logs or an minimal example?
You can enable the logs by creating the driver with:
const driver = neo4j.driver(<your url>, <your credentials>, {
...// other configurations,
logging: neo4j.logging.console("debug")
})
See: https://neo4j.com/docs/api/javascript-driver/5.9/function/index.html#static-function-driver
Hi @gchicoye, do you have some logs or an minimal example?
You can enable the logs by creating the driver with:
const driver = neo4j.driver(<your url>, <your credentials>, { ...// other configurations, logging: neo4j.logging.console("debug") })
See: https://neo4j.com/docs/api/javascript-driver/5.9/function/index.html#static-function-driver
I get a TS error here...
Property 'logging' does not exist on type '{ driver: (url: string, authToken?: AuthToken | undefined, config?: Config | undefined) => Driver; hasReachableServer: (url: string, config?: Pick<Config, "logging"> | undefined) => Promise<...>; ... 68 more ...; notificationFilterMinimumSeverityLevel: EnumRecord<...>; }'.ts(2339)
Hi, any idea on this?
Can you try to ignore the ts definition?
const driver = neo4j.driver(<your url>, <your credentials>, {
...// other configurations,
// @ts-ignore
logging: neo4j.logging.console("debug")
})
I will investigate the ts type error.
Hey,
Done ! I've done a lot of updates on my code, now it looks like the following
const upsertDbEntry = async (dbEntry:DbEntry, txc:Transaction)
:Promise<QueryResult> => txc.run(
`
MERGE (user:User{first_id: $userId })
ON CREATE SET user.created_at = timestamp()
ON MATCH SET user.updated_at = timestamp()
MERGE (audience:Audience{mediarithmics_id: $segmentId })
ON CREATE SET audience.created_at = timestamp()
ON MATCH SET audience.updated_at = timestamp()
MERGE (user)-[rel:BELONGS_TO]->(audience)
ON CREATE SET rel.created_at = timestamp()
`,
dbEntry,
);
const deleteDbEntry = async (dbEntry:DbEntry, txc:Transaction)
:Promise<QueryResult> => txc.run(
`MATCH (user:User{first_id:$userId})-[belong:BELONGS_TO]->(audience:Audience{mediarithmics_id: $segmentId})
DELETE belong`,
dbEntry,
);
export const saveChunkData = async (dbEntries:DbEntry[]):Promise<boolean> => {
const session = driver.session();
const txc = session.beginTransaction();
try {
for (let i = 0; i < dbEntries.length; i += 1) {
const dbEntry = dbEntries[i];
if (dbEntry.action === 'UPSERT') upsertDbEntry(dbEntry, txc);
if (dbEntry.action === 'DELETE') deleteDbEntry(dbEntry, txc);
mediarithmicsLinesCounter.inc();
}
await txc.commit();
return true;
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
await txc.rollback();
// eslint-disable-next-line no-console
console.log('rolled back');
return false;
} finally {
await session.close();
}
};
export const saveChunkDataWithRace = async (dbEntries:DbEntry[]):Promise<void> => {
const endPromise:Promise<boolean> = new Promise((resolve) => {
setTimeout(() => {
resolve(false);
}, 60000);
});
const promises:Promise<boolean>[] = [
saveChunkData(dbEntries),
endPromise,
];
const result = await Promise.race(promises);
if (!result) {
// eslint-disable-next-line no-console
console.log(`${new Date().toString()} - Commit timeout`);
process.exit(1);
}
};
I get the following logs from debug (the ts-ignore
trick made the job :))
1687880367930 DEBUG Connection [0][bolt-2411] C: RUN
MERGE (user:User{first_id: $userId })
ON CREATE SET user.created_at = timestamp()
ON MATCH SET user.updated_at = timestamp()
MERGE (audience:Audience{mediarithmics_id: $segmentId })
ON CREATE SET audience.created_at = timestamp()
ON MATCH SET audience.updated_at = timestamp()
MERGE (user)-[rel:BELONGS_TO]->(audience)
ON CREATE SET rel.created_at = timestamp()
{"action":"UPSERT","userId":"7c5c2e7fb4cb4eba77e2daa02a4ce301","segmentId":"36595"} {}
1687880367930 DEBUG Connection [0][bolt-2411] C: PULL {"n":{"low":1000,"high":0}}
1687880367932 DEBUG Connection [0][bolt-2411] S: SUCCESS {"signature":112,"fields":[{}]}
However, I usually cannot get the commit to perform, and so nothing happens, my timeout function is executed (nothings happens for minutes otherwise) and container restarts...
You should resolve the promise returned by the tx.run. You can do by:
if (dbEntry.action === 'UPSERT') await upsertDbEntry(dbEntry, txc);
if (dbEntry.action === 'DELETE') await deleteDbEntry(dbEntry, txc);
Bug Report
While updating my Neo4J database (community edition) with the following script
I get the following uncatchable error.
On my server, we get the following log
My Environment
Javascript Runtime Version: 18.16.0 Driver Version: 5.7.0 Neo4j Version and Edition: docker Neo4j:latest - 5.6 Community edition Operating System: Debian 10 for Server, node:lts-alpine for Client (18.16.0)