#NEWLINE# @ web . authenticated #NEWLINE# @ web . asynchronous #NEWLINE# def post( self , taskname ) : #NEWLINE# #INDENT# '\nExecute a task by name and wait results\n\n**Example request**:\n\n.. sourcecode:: http\n\n  POST /api/task/apply/tasks.add HTTP/1.1\n  Accept: application/json\n  Accept-Encoding: gzip, deflate, compress\n  Content-Length: 16\n  Content-Type: application/json; charset=utf-8\n  Host: localhost:5555\n\n  {\n      "args": [1, 2]\n  }\n\n**Example response**:\n\n.. sourcecode:: http\n\n  HTTP/1.1 200 OK\n  Content-Length: 71\n  Content-Type: application/json; charset=UTF-8\n\n  {\n      "state": "SUCCESS",\n      "task-id": "c60be250-fe52-48df-befb-ac66174076e6",\n      "result": 3\n  }\n\n:query args: a list of arguments\n:query kwargs: a dictionary of arguments\n:reqheader Authorization: optional OAuth token to authenticate\n:statuscode 200: no error\n:statuscode 401: unauthorized request\n:statuscode 404: unknown task\n        ' #NEWLINE# ( args , kwargs , options ) = self . get_task_args ( ) #NEWLINE# logger . debug ( "Invoking a task '%s' with '%s' and '%s'" , taskname , args , kwargs ) #NEWLINE# try : #NEWLINE# #INDENT# task = self . capp . tasks [ taskname ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# raise HTTPError ( 404 , ( "Unknown task '%s'" % taskname ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . normalize_options ( options ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise HTTPError ( 400 , 'Invalid option' ) #NEWLINE# #UNINDENT# result = task . apply_async ( args = args , kwargs = kwargs , ** options ) #NEWLINE# response = { #NEWLINE# #INDENT# 'task-id' : result . task_id , #NEWLINE# #UNINDENT# } #NEWLINE# th = Thread ( target = self . wait_results , args = ( result , response ) ) #NEWLINE# th . start ( )