How to add background job to queue from server script

Can anyone give insights on how to add a rest api call i have to make to some sms gateway via background job from server script. This sms gateway sometimes takes long to respond and that makes my server script to respond very late.

an example:
frappe.utils.background_jobs.enqueue(method=frappe.sendmail, queue=β€˜short’, timeout=300, is_async=True, **email_args)

1 Like

It is showing invalid python code

Or is it possible to call whitelisted function from server script

Check the syntax carefully. Remove the ’ from method definition. Define args outside the call or define in a dict(what=ever) like call

2 Likes

it was showing frappe.utils.background_jobs does not exist. so i tried doing frappe.enqueue. but now it is showing name β€˜apply’ is not defined

is it possible to do import in server script

i did it via hooks after. If the server script was capable of doing our requirement it would have been easy for System Administrators to do small tasks without rely on a programmer. Hope the feature will be available in the Future.

you should not go into the hooks but anyway. To help sb needs the whole ladscape and requirement. We can only direct you to the relevant functions and shed some light towards the solution.

1 Like