I was working to understand asyn handler in frappe
In Async Tasks
How we can add new Task in Async process, As we can not add any task from UI ?
How i can attach handler to Async in from python code, right now i am using “override_whitelisted_methods” to perform this functionality ?
Can I get a bit more information that how I can add another frappe.async.handler
I added one more but it’s not getting included in cmd list of frappe.async command. Hopefully above 2 questions can help us to get answered these queries as well.
on the basis of submitting a sales Order, we are trying to raise 10 material requests automatically. So i am using frappeclient on same server.
#@celery_task()
#@frappe.async.handler
def copy_doc():
# hack! pass event="bulk_long" to queue in longjob queue
print frappe.flags
#print doc
print frappe.local
print frappe.__dict(args)
form_dict = frappe._dict()
print cmd
user = (frappe.session and frappe.session.user)
if not pwd:
return False
client = FrappeClient("localhost", user)
if not client:
return
copy_doc = frappe.new_doc(form_dict['doctype'])
I am calling this function from another document
def mr_doc():
user = (frappe.session and frappe.session.user) or doc_dict['modified_by'] or "Administrator"
result = run_async_task.delay(site=frappe.local.site, user=user, cmd='sync_doc', form_dict=form_dict)
As above command is function definition not an another method, i am using functionality of async_ping().
but async_ping is defined as frappe.async.handler
when i am using same as command then it didnt worked.
Hopefully you can assist here.
Thanks Rmehta
I just found a method name run_async_task in async.py but its not getting used anywhere in frappe code. This functions creates Async Task Doctype document. Can you give brief information why its not getting used anywhere.
Thanks @anand
apologies for typo error as i have used cmd = 'copy_doc' only. and i have done change is configuration to enable debug level logs using -l debug.
I am calling this function mr_doc() from hooks.py in doc_events as given below
AttributeError: 'copy_doc' object has no attribute 'queue'
[2015-11-16 05:17:06,477: ERROR/Worker-6] frappe.tasks.run_async_task[2ca29d26-ec82-4c39-941f-983a5db9c57f]: Exception in running sync_doc: ["Traceback (innermost last):\n File \"/home/frappe/frappe-bench/apps/frappe/frappe/tasks.py\", line 160, in run_async_task\n execute_cmd(cmd, from_async=True)\n File \"/home/frappe/frappe-bench/apps/frappe/frappe/handler.py\", line 92, in execute_cmd\n method = method.queue\n File \"/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/celery/local.py\", line 143, in __getattr__\n return getattr(self._get_current_object(), name)\n AttributeError: 'copy_doc' object has no attribute 'queue'\n"]
I have gone through whole Code then i figure out that execute.cmd uses queue for method. How i can define this queue to execute this method @pdvyas Hopefully you can assist here if i am missing any point to write this function.