Best way of achieving triggering jobs more often than every minute
I currently have a job that runs every minute, but it's not frequent enough. The cron expression only allows for a minute as standard. Is there a way around it?
7 Replies
Hi @CamBlackwood. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Wasp's job scheduling system, which uses pg-boss as its executor, only supports a minimum resolution of one minute for recurring jobs. This is a limitation of pg-boss itself, as it only supports cron expressions with minute-level precision. There is no built-in way in Wasp to schedule jobs more frequently than every minute (e.g., every 10 seconds) using the current cron-based scheduling system.
This limitation is confirmed in community discussions, where it is stated: "The lowest resolution is 1 minute for our jobs unfortunately (we are using PgBoss for jobs scheduling)" Discord support thread.
If you need jobs to run more frequently than every minute, you would need to look for alternative approaches outside of Wasp's current job scheduling capabilities, as the knowledge sources do not mention any official workaround or support for sub-minute scheduling.
----------------------
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?
Inside the every minute job can you just run the code, wait 30 seconds, then run the code again?
yeah I'm thinking this could be the best approach. Basically the use case is I need to update records that are "out of date", and I was just grabbing one every minute, but now there are over 2000 rows so if I want them to update daily, it's not actually possible
Just out of curiosity, why are you limited to only one row per job run? 🤔
I’m not really, but it made the architecture/readability of the code much simpler - taking batches could potentially result in race conditions
@CamBlackwood
The cron syntax sometimes for allows optional sixth field which is for seconds. Using that would fix this problem.
cron-parser
which is used by pg-boss
does support that syntax https://www.npmjs.com/package/cron-parser
The question is does pg-boss
support it?
*/5 * * * * *
is every 5 seconds in that syntax.
You could try it out and see if it works, I'm not 100% sure here.Thanks, I'll try this!