Queue, prisma and postgres
lludol
HOBBYOP

2 years ago

Hello,

I have a classic rest API with Fastify (node.js) that is connected to two databases:
postgres
mongo
Then, I also have a queue instance, it's also a Fastify but for the queue I am using https://github.com/mgcrea/prisma-queue (why? because it uses the lock feature of postgres).

Both use Prisma to connect to the database.

My problem is that the second instance has some cron job that are executed for example every day at 6am but sometimes they can't finish their job because there is this error:
PrismaClientKnownRequestError

Invalid prisma.queueJob.count() invocation:
Can't reach database server at monorail.proxy.rlwy.net:30404
Please make sure your database server is running at monorail.proxy.rlwy.net:30404.

To handle the prisma connection, I instanciate on both instances the prisma client through a Fastify plugin that will save the prisma instance to share it with either the routes or the jobs.

Is there something I need to configure on Railway?
I already have disabled the sleeping instance feature.

Do I need to switch and use for example a queue library that use redis for example?
Is it because of the "serverless" state of railway that the connection is terminated?

Here my project ID where you have the 4 instances: 7c6b4b90-5182-4863-88ba-99fbd7a64056

8 Replies

2 years ago

please do not create duplicate threads


2 years ago

railway is not serverless at all, apps are not stopped after any amount of time unless you have app sleeping enabled.

you should also be using the private network to avoid egress fees when connecting to the database


lludol
HOBBYOP

2 years ago

the bot closed my thread because I didn't put the project id, I didn't know what else to do


lludol
HOBBYOP

2 years ago

I could not manage to make private network work when I tried it few weeks ago. I can try again (between the backend and the queue instance)


lludol
HOBBYOP

2 years ago

For the DATABASEURL, I am using the ${{Postgres.DATABASEURL}}, doesn't it use per default the private network?


2 years ago

that depends on when you deployed the database, simply check the value


lludol
HOBBYOP

2 years ago

I put the DATABASEPRIVATEURL env Var. Same for Mongo at the end


2 years ago

perfect!


Loading...