Cron / Background jobs / Tasks
In SolidJS which also uses Nitropack under the hood it was possible to setup cron jobs using Nitropack.
See docs here: https://nitro.build/guide/tasks
And specific implementation in SolidJS: https://github.com/solidjs/solid-docs/issues/964
AFAIK SolidJS did nothing to enable this and it just came out of the box by using Vinxi and Nitropack.
I just tried the same with Tanstack Start and while I can add those configurations in
app.config.ts
the tasks seem to be ignored.
Do you guys know by any chance how to enable that feature somehow?
Thanks ๐
Disclamer
- I know this out of scope for this so no worries if nobody wants to spend time on it; in fact thanks for this amazing library already ๐
- I know ideally one should run tasks in a separate process/thread since node is single threaded; my specific use case is for an app that works in a specific timezone and has traffic downtime during the night and I can run some simple and fast cleanup tasks.Tasks - Nitro
Nitro tasks allow on-off operations in runtime.
GitHub
[Other]: Tasks ยท Issue #964 ยท solidjs/solid-docs
๐ Explain your issue Reference Discord conversation: https://discord.com/channels/722131463138705510/1310190736670457856/1310190736670457856 I was able to make background jobs/tasks work in Solid S...
20 Replies
exotic-emeraldโข9mo ago
how does your app.config.ts look like?
it might be we just don't pass on those things to vinxi
generous-apricotOPโข9mo ago
Here you go
exotic-emeraldโข9mo ago
i checked, we forward this to vinxi
(everything in server)
so this should work
in terms of vinxi configuration at least
which vinxi version are you using?
generous-apricotOPโข9mo ago
0.5.1
exotic-emeraldโข9mo ago
try downgrading to 0.4.3
maybe it broke in vinxi?
and nitro
generous-apricotOPโข9mo ago
tried downgrading and it's still not working
Something that I remember used to happen in SolidJS was that there was a message saying "registered task XYZ" or something along those lines.
That's also nowhere to be found.
Hold on I can just push this into a repository so that you have a reproducible env
exotic-emeraldโข9mo ago
so maybe the cron.ts file is not where it should be?
generous-apricotOPโข9mo ago
If that was the cause it would say something like "task not registered because it was not found"
Hold let me give you the exact messages
Nevermind. I can't make them work in SolidJS so yeah something broke with nitro probably.
Thanks anyway ๐
exotic-emeraldโข9mo ago
ah
fair-roseโข9mo ago
any news on this ?
fair-roseโข9mo ago
GitHub
Nitro Tasks API ยท Issue #1974 ยท nitrojs/nitro
Nitro tasks allow on-off operations in runtime. Docs: https://nitro.unjs.io/guide/tasks ### Tasks - [x] Initial Implementation (#1929) - [x] Write documentation section (PR welcome!) - [x] Stabiliz...
fair-roseโข9mo ago
i guess we'll just have to wait then
generous-apricotOPโข9mo ago
Nope. I've posted here: https://github.com/nitrojs/nitro/issues/1974#issuecomment-2542516974 but apparently it's not something that was ever available
I guess I've hallucinated it
fair-roseโข9mo ago
:/
generous-apricotOPโข9mo ago
Boring hallucination if you ask me
fair-roseโข9mo ago
how do you go about scheduling tasks then ? any recommendation ?
generous-apricotOPโข9mo ago
Luckily for me I can delay the implementation for a few months but if I had to implement it today I'd probably have a separate worker / server running the background task. I'd put the code for it inside the current codebase (or maybe create a monorepo with multiple packages) and just run
tsx cron-script.ts
in some worker.
If you want to keep everything in the same app/deployment then I'd probably use concurrently
to run both the server and the cron tasks script (probably using node-cron
or similar) but it's not clear how production ready concurrently
is
If concurrently
is not good for prod I'd go with Docker + linux crontab
If you are doing serverless I have no idea as I tend to avoid that worldfair-roseโข9mo ago
Thanks for the insight. I'm running both services (along with the db) in a docker compose for now
the issue with something like concurrently (unless im wrong) is that there is no proper way to restart the job scheduler if it crashes, is there ?
generous-apricotOPโข9mo ago
That's right. If you are already using
docker-compose
maybe a separate container is the best option for you. You should be able to handle restarts as well.extended-salmonโข8mo ago
You can also try PM2 to run a cron on the same or another process.