Next.js Discord

Discord Forum

Code only works on my dev environment

Answered
Brittany posted this in #help-forum
Open in Discord
Avatar
BrittanyOP
I have a scraper that runs once every 5 minutes. It was working fine until I inserted more things to do. I don't know exactly what's going on, the code don't show any error on logs. But database don't get fully updated, just get some data inserted but a huge part of it don't get there.

The code works fine when I use on my computer, using dev environment and triggering the cron job (the memory usage for next-server reaches less than 300MB). But once I deploy to Vercel, it starts it behaviour. I will attach the code on this post.

I also increased the cron job duration to 300s.
Image
Answered by Brittany
What I did to fix this is to handle all promises first before starting creating the other array of promises
View full answer

9 Replies

Avatar
BrittanyOP
I've just got this error
Image
Avatar
BrittanyOP
Some random arrows are showing once in a while
Image
Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"PrismaClientKnownRequestError: \nInvalid prisma.character.update() invocation:\n\n\nTransaction API error: Transaction with { txnNumber: 3 } has been aborted.","reason":{"errorType":"PrismaClientKnownRequestError","errorMessage":"\nInvalid prisma.character.update() invocation:\n\n\nTransaction API error: Transaction with { txnNumber: 3 } has been aborted.","code":"P2028","name":"PrismaClientKnownRequestError","clientVersion":"5.6.0","meta":{"error":"Transaction with { txnNumber: 3 } has been aborted."},"stack":["PrismaClientKnownRequestError: ","Invalid prisma.character.update() invocation:","","","Transaction API error: Transaction with { txnNumber: 3 } has been aborted."," at ni.handleRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:124:6817)"," at ni.handleAndLogRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:124:6206)"," at ni.request (/var/task/node_modules/@prisma/client/runtime/library.js:124:5926)"," at async l (/var/task/node_modules/@prisma/client/runtime/library.js:129:10023)"," at async /var/task/.next/server/app/api/crons/getPlayersOnline/route.js:5:179140"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: PrismaClientKnownRequestError: ","Invalid prisma.character.update() invocation:","","","Transaction API error: Transaction with { txnNumber: 3 } has been aborted."," at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)"," at process.emit (node:events:529:35)"," at emit (node:internal/process/promises:149:20)"," at processPromiseRejections (node:internal/process/promises:283:27)"," at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]}
Am I doing too many reqs to the database? I'm using MongoDB on Atlas Cloud
Because I'm using the same database in my dev environment and it shows no error
Is it a prisma problem?
Avatar
BrittanyOP
What I did to fix this is to handle all promises first before starting creating the other array of promises
Answer