I need to create a cron job
I need to create a cron job to update user info each hour, for example I need to increment credits of a user. How can I set the cron job?
4 Replies
Hi @pollastrepiupiu. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Creating a Cron Job in Wasp
You can create a recurring job in Wasp to increment user credits hourly using the
job
declaration with a schedule. Here's how to set it up:
1. Define the Job in your .wasp file
The cron expression 0 * * * *
means "run at minute 0 of every hour". You can customize this using Crontab guru if you need a different schedule.
2. Implement the Worker Function
Create the worker function that will be executed according to the schedule:
For TypeScript:
That's it! Wasp will automatically schedule and run this job every hour. The job will persist between server restarts and can be retried if it fails.
Note: This requires PostgreSQL as your database since it uses the PgBoss executor. Make sure your app.db.system
is set to PostgreSQL
in your Wasp file.
Recurring Jobs Documentation
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @pollastrepiupiu, 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?Will authomatically run If I work in local?
Wohooo @pollastrepiupiu, you just became a Waspeteer level 2!
Will authomatically run If I work in local?Yep, when we run locally we do spin up a full DB with the necessary extensions, so everything will run smoothly 💫