Coder Social home page Coder Social logo

Comments (8)

gchicoye avatar gchicoye commented on June 3, 2024

Hey, any news on that? Thanks!

from neo4j-javascript-driver.

gchicoye avatar gchicoye commented on June 3, 2024

Hi, would it be possible to get some insight on this? Thanks!

from neo4j-javascript-driver.

bigmontz avatar bigmontz commented on June 3, 2024

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

from neo4j-javascript-driver.

gchicoye avatar gchicoye commented on June 3, 2024

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)

from neo4j-javascript-driver.

gchicoye avatar gchicoye commented on June 3, 2024

Hi, any idea on this?

from neo4j-javascript-driver.

bigmontz avatar bigmontz commented on June 3, 2024

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.

from neo4j-javascript-driver.

gchicoye avatar gchicoye commented on June 3, 2024

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...

from neo4j-javascript-driver.

bigmontz avatar bigmontz commented on June 3, 2024

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);

from neo4j-javascript-driver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.