Schedule 'signature'?
Has there been thought to dedupping scheduled calls at the
runAt
/runAfter
execution time of multiple invocations with the same name/args signature?
Eg: if I have a updateUser
mutation that schedules an action of doThing
with {userId}
as the args to runAfter 60 seconds, could additional schedules of the same signature be dedupped into this same schedule runner so that only one invocation happens per 60 seconds?5 Replies
I understand I could build a queue in a table and drain it through a cron or something, but seems to be recreating the wheel to a degree
aside from the cron approach, you could read and write from a table that captures what you plan to schedule. On the write side you could avoid reading if there's been something scheduled recently. Or on the read side (in the scheduled function) avoid executing if something has happened recently. Or if it's being duplicate- scheduled from within one function, you could abstract the scheduler to do the custom de-duping.
It sounds like you're interested in both de-duping but also general rate limiting. By default I could see it being surprising to de-dupe scheduled functions, but maybe some helper to make it easy to keep track of what's scheduled, were you provide a custom function, would be helpful?
We have no plans to do general deduping, since the exact logic depends on the applicationa nd sometimes you don't need deduping. As @ian pointed out, you can do deduping when you schedule. Or you can make the scheduled functions themselves be idempotent by checking if the desired side effect has been achieved by checking/recording to the database.
Unfortunately the side effects are external, so theres nothing to check locally.
If there was a helper to query the scheduler queue, that could be of interest, so I could conditionally schedule based on the results
Yeah, good point. We might allow querying the scheduler queue in the future. Although this might be by function name or scheduled id returned at time of scheduling, not sure if we are going to index scheduled functions by arguments. You can implement this manually by inserting a record at the same time you schedule (this is especially easy from mutation since it is transactional with the scheduling), and deleting it at the beginning of your scheduled function run.