I have written a sequence to gather all subtasks, along with their custom fields of tasks in a project. However, the execution time is long - several minutes for one project, about 13 min for 3 projects. I would like to run the sequence asynchronously, but can’t find examples of how to integrate asyncio or aiohttp modules with the asana module, specifically asana’s client class & ‘find_by_id’ tasks function. Is there a way to use this function with an asyncio session? My current approach for creation of the subtask dataframe for a list of projects is below:
########## dataframe comprised of all subtasks ##########
time.start()
df_s=pd.DataFrame()
for j in s3:
l_path=r'/projects/'+j+r'/tasks' #api path for all tasks in the requisite project
i_tasks = t.request(method='get',path=str(l_path),verify=False) #all tasks for a particular project
for k in i_tasks:
st=t.request(
method='get',
path=str(r'/tasks/'+(k['gid'])+r'/subtasks'),
verify=False
)
if st == []:
pass
elif st != []:
for l in st:
s=t.tasks.find_by_id(task=l['gid'],headers=new_header) #get complete results for a particular subtask
d=pd.json_normalize(
s,
record_path=['custom_fields'],
meta=['gid','name','parent','assignee','completed'],
record_prefix='cf_',
)
parent_name=[]
parent_gid=[]
assignee_name=[]
assignee_gid=[]
for m in d['parent']:
parent_name.append(m['name'])
parent_gid.append(m['gid'])
for n in d['assignee']:
if n == None:
assignee_name.append(None)
assignee_gid.append(None)
else:
assignee_name.append(n['name'])
assignee_gid.append(n['gid'])
d['parent_name']=parent_name
d['parent_gid']=parent_gid
d['assignee_name']=assignee_name
d['assignee_gid']=assignee_gid
d_clean=d.drop(['parent','cf_enum_options','assignee'],axis=1)
df_s=df_s.append(d_clean,ignore_index=True)
time.stop()
########## end ##########