How can I cause a job to be scheduled for a future time in Frappe? This seems like it should be a simple task but I can’t find a way to do it efficiently. In my application, I have ‘Tasks’. Each Task can be assigned a due date. I want to a notification to be created when the due date is reached.
So far, the only way that I’ve found to do this is to create a scheduler entry via hooks.py that runs every 5 minutes and checks the due dates of all Tasks looking for ones that are due soon. This kind of polling approach is not desirable as it means that if I schedule a task for 3 minutes from now, in the absence of a bunch of janky logic, it’s possible that a notification will never get created. Also, setting the scheduler for anything less than 5 minutes is a bad idea since it will just be blindly checking the whole Task doctype for matching events, which can will become burdensome on the system as the Tasks list grows.
hello @Joshua_Restivo
you need to provide more details about what you want to achieve,
I know that Auto Email Report can do schedule notifications If that is what you meant
Or in the notification docType you can write a condition based on one of the Task Fields
by set [Send Alret On] = Dayes Before and in the [Reference Date] = assign the field
Frappe’s scheduler is an overlay for Linux’s cron utility. To my knowledge, cron doesn’t have any concept of “do X once at time Y”. If you need that, an additional layer is necessary.
Like @Gharieb points out, the Notification is Frappe’s built-in way of implementing one-time events, and it’s a lot more versatile than the name suggests. Paired with server scripts, you could implement quite a bit of complexity. If Notifications don’t suit your needs, you’ll need to create your own scheduler event like you mention (either through hooks.py or as a server script).
It sounds like you’re on the right track. I’m not totally understanding your concerns, though. Why would a task scheduled for 3 minutes from now be missed by a scheduled job that runs every five minutes?
As for burden, polling the sql backend quickly and efficiently is what Frappe’s ORM is designed to do. Fetching a list of all tasks due on a particular day would be pretty trivial computation, even if you ran it every few minutes. Most installations have many jobs like this running constantly in the background. Frappe is not particularly unusual in this regard.