itsyoboieltr
itsyoboieltr6mo ago

Cron job with tRPC

can I make a cron job using tRPC? I would like a tRPC endpoint to be called periodically by the same Next.js application that also hosts the tRPC api, meaning I cannot use an external service to make the request to the app. Is this possible somehow? In plain typescript, this would be something like a setInterval function that would call the server side function caller every n seconds.
5 Replies
itsyoboieltr
itsyoboieltrOP6mo ago
for reference: Elysia is using Croner to implement cron jobs https://github.com/hexagon/croner, I wonder how would this be used in the context of tRPC with a next.js app
alessandroooo
alessandroooo2mo ago
did you find a solution for this?
itsyoboieltr
itsyoboieltrOP2mo ago
I used a github action to manually call my trpc procedure. It's not the best approach, because I needed to create a "service account" to login before making the request, so that I can call the procedure from outside of the app. As the github runner is on a different machine. I still wish trpc supported cron jobs to make it easier! In addition, nowadays instrumentation.ts is also stable in Next.js. Probably this could also be used for scheduling something, but I have not explored this extensively.
alessandroooo
alessandroooo2mo ago
I'll check this out tomorrow, thx switched to nodejs nodejs + vite

Did you find this page helpful?