So I would like to know the best practice for accomplishing the following:
def execute_expensive_operation(obj):
#create instance of a model storing the relevant info to load the JSON into the template
#includea `task` field that stores the name of the asynchronous task (obj.pk) so that the JSON can be loaded if the name of the task is known
def test_view(request):
list_of_objects = [...] #will actually be dynamically loaded from the request
task_dict = {}
for obj in list_of_objects:
task_dict[obj.pk] = execute_expensive_operation(obj).delay(obj.pk) #this could take a while, put it on queue (using celery)
context = {"tasks":task_dict}
return render_to_response("template.html",context)
"template.html"
is going to load the JSON relevant to each obj
in a row in a table
As this is set up above, the task_dict
will actually be filled with AsyncResult
objects rather than JSON. What I want to do, is dynamically load any row once the Asynchronous task related to that row has completed.
note:
I apologize for the non-specific methods, this is not something that is meant to be for anything specific, but more so for a general case that I have to deal with in a variety of different places. If there is any missing information, please let me know so that I can include it.