How to Trigger Server Side code from Timers?

When a workflow event happens, I want to create a 2-hour timer with a reference to the doctype. I want the timer to be periodically checked on the server so that after exactly 2 hours, the timer can trigger a custom script.

Is there any kind of timer mechanism in ErpNext to support something like this?

@James_Houx I have been looking for away to do something similar and until now the only way that I have found is to create a new Module manually and add the desired method path/namespace to the scheduler_events section in the Hooks file.

I hope that I was helpful.

1 Like

Thank you @kid1194! Your feedback is helpful!

I am presently thinking the most flexible implementation for my needs is to have a job that runs every single minute. The job can do a query to evaluate outstanding data and decide whether or not to trigger an event. By always doing the query and decision making every minute, I have the ability for changed conditions that would cancel the event to implicitly cancel it. This is more robust than creating an explicit timed event that has to be manually canceled when a data change should cause a cancellation. It should also be less bug-prone.

1 Like

Hi James,

For a “run every minute” job, @kid1194’s suggestion of creating 'scheduler_events' in ‘hooks.py’ would definitely do the trick. :+1:

Here’s the link to the official documentation on Scheduler Events, if you haven’t found it already.

I actually just-released an alternative scheduling App this week. It’s probably overkill for your needs. But later on, if you’re planning to build a lot more automation, might be worth taking a look :man_shrugging:

1 Like

I’ll check out the app!
Thanks @brian_pond