Replies: 2 comments 3 replies
-
|
How could crons fit in with "repeatable workflows" ? For example, right now I have triggered repeatable / stoppable workflows in my app via: const REPEAT_INTERVAL = 1 hour *I have hooks as well for stopping this repeat cycle and the sleep duration accounts for the time it takes so it always repeats on a stable interval like a cron would, the duration of each individual workflow doesn't matter (as long as its less than the interval duration) This avoids having the same workflow have the same steps / loop hundreds of times and makes each individual run more easily debuggable. But this is also annoying, and if one workflow encounters an error then it stops the whole repeat cycle. I would prefer something like And this way, on startup, say in instrumentation.ts for Nextjs, you can call For once an hour. The benefit here is no .schedule attribute on the workflow function, and also crons don't have to be registered or pre configured ahead of time. You could start a repeating cron at any point (e.g. a user signs up, you start a cron workflow just for them, or increase the frequency when they upgrade to a higher tier, so pro tier gets 4x an hour sync or whatever and free is 1x an hour) there are lots of ways this is beneficial. And then you could also STOP the cron at any point via something like The actual function names and DX outlined above is random but I think triggering / creating / stopping any cron for any workflow function via code would be awesome. I can see how this would throw a wrench in the proposed vercel implementation bc that is leaning on the existing vercel cron product but I'm sure there's a way! Same with graphile cron tab, seems to be a pre configured file too. Maybe cron could just be part of the workflow runtime rather than a world implementation detail? Via durably chaining / scheduling with sleep() etc in coordination with hooks? |
Beta Was this translation helpful? Give feedback.
-
|
Specifying the schedule at build-time is way too unflexible. That might work for some cleanup jobs, but it doesn't allow for any configurations by admins (e.g. when/how often shall we fetch currency rates), and it can't handle user-defined jobs at all. An example for the latter would be sync jobs with external providers that my users could set up (within bounds, of course). The developers don't always know what's best, and having to rebuild and redeploy for any adjustment doesn't feel right. 😉 I found this issue because I checked whether I could hook into the Graphile worker (add tasks and jobs), but that doesn't seem to be possible. And of course, I would enjoy the benefits of running jobs as workflows, with streamed logs, retries etc. An alternative would be a meta cron which runs every minute and checks if there's anything to do... but that would blow up the logs, and would probably be easier to implement background function started in |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Putting this up from an internal discussion to track native cron support in workflow. This is the simplest way to get cron support and we can iterate from there on feedback and features.
Schedules are defined on workflows
These schedules are extracted and validated at build time and included in the manifest. When building on vercel, it would also compile into Build Ouptut API cron expressions:
This means we have a new generated route on user deployments that authenticates requests against a
CRON_SECRETenv variable (respected by vercel cron) and then it runsstart(myWorkflow, [])For postgres world, crons would be powered by graphile crontab.
startWorld()would be responsible for setup and teardown of cron jobs. Essentially - whenstartWorldis run in a production environment, it compares the build manifest crons with the graphile crons and makes any updates necessaryFor local world, we'll do it in-process
Open questions at this time:
Beta Was this translation helpful? Give feedback.
All reactions