Next.JS Background Tasks

I need help with something driving me crazy. This is a Next.Js problem not an uploadthing problem but I’m curious if anyone has ever faced this issue with Next.JS instrumentation. I have a upload-thing.js file that handles file uploads. This file has import server-only at the top. I have 3 long running tasks to perform after successful upload, I decided to introduce a Queue to my setup. I used BullMQ library. The queue and worker files are all part of the Next.JS application. THE CHALLENGE: I need to start the Queue worker somewhere, somehow. This queue worker is a function I need to call once, preferably during boot. THE PROBLEM: Server fails to start apparently because the “parent component” is a client component. This parent component happens to be the instrumentation.ts file that imports the file that contains the “import server-only” line.
4 Replies
Josh
Josh13mo ago
if it's long running it shouldn't be in the next stack the backend of a next stack runs on lambdas with a max run time of 300 seconds, and that's only if you manually configure it like that
Endgame1013
Endgame101313mo ago
If you don’t want to develop a separate backend, you could use a service like SST’s queues for this: https://docs.sst.dev/queues
Queues | SST
Queue up work to be processed
nero
neroOP13mo ago
Thank you very much. This appears to be the source of my problem. I need to extract the Queue worker away from Vercel Thank you. I'll check this out if it works for my use case
Josh
Josh13mo ago
im currently starting a project with sst like endgame suggested, so far it seems pretty sick
Want results from more Discord servers?
Add your server