Cron jobs running locally?

This is almost certainly a really stupid question, but I assume if the server is running locally, cron jobs will still fire and therefore update my database (when updating it in the job, of course)
8 Replies
kapa.ai
kapa.ai3mo ago
Hi @CamBlackwood. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, you're correct. If your server is running locally, cron jobs defined in your Wasp application will still execute as scheduled. This is because cron jobs in Wasp are not dependent on the deployment environment but on the server runtime. For example, in Wasp, you can define a cron job like this:
job SendInternalStatsEmail {
perform: import perform from "@ext/jobs/sendInternalStatsEmail.js",
repeat: {
cron: "0 2 * * *",
argument: {=json "foo": [1, 2, 3] json=}
}
}
job SendInternalStatsEmail {
perform: import perform from "@ext/jobs/sendInternalStatsEmail.js",
repeat: {
cron: "0 2 * * *",
argument: {=json "foo": [1, 2, 3] json=}
}
}
This job will execute the perform function imported from sendInternalStatsEmail.js at 2 AM every day, passing the argument { "foo": [1, 2, 3] } to it. This will happen regardless of whether your server is running locally or in a production environment. However, it's important to note that the persistence of these jobs can depend on the implementation. For instance, if you're using an in-memory solution like node-cron, any pending jobs will be lost if the Node.js process restarts. On the other hand, a persistent solution like pg-boss will keep track of jobs even when the server restarts. You can read more about this in the Github Issue discussing support for background jobs (https://github.com/wasp-lang/wasp/issues/530). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @CamBlackwood, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
CamBlackwood
CamBlackwoodOP3mo ago
Thanks @kapa.ai 🫡
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- You're welcome! If you have any more questions about Wasp, feel free to ask. Happy coding! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @CamBlackwood, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho3mo ago
Good job Kapa 👍
martinsos
martinsos3mo ago
@CamBlackwood , I am interested in the motivation behind your question: is it problematic for you that they are running during local development? I guess you might have a situation where you would rather not have some of them run during local development, because they migth have effects you don't want to happen? If so, how have you solved it at the moment?
CamBlackwood
CamBlackwoodOP3mo ago
@martinsos not problematic at all 🙂 I was being lazy and just wanted to watch it run once instead of putting it into an api endpoint to fully test it (I was pretty confident it was going to work first time, which it did)
martinsos
martinsos3mo ago
Ok you are not the only one though, I also had that situation. Would be nice to able to trigger the job via CLI or something, during development! Or maybe that is a bit too niche situation hm not sure.
CamBlackwood
CamBlackwoodOP3mo ago
this would be a really handy feature I think, as it's considerable overhead to convert it to an api endpoint
Want results from more Discord servers?
Add your server