Skip to content

Commit

Permalink
Merge pull request #6037 from tomachalek/async_tasks_fix
Browse files Browse the repository at this point in the history
Async tasks fix
  • Loading branch information
tomachalek authored Oct 5, 2023
2 parents 55cd0cf + b16f9b2 commit 6dd8baf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
30 changes: 13 additions & 17 deletions lib/action/model/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,24 +329,20 @@ async def update_async_task_status(self, curr_at: AsyncTaskStatus) -> bool:
returns:
True if job was found (and updated) else False
"""
backend = settings.get('calc_backend', 'type')
if backend in ['rq']:
worker = bgcalc.calc_backend_client(settings)
aresult = worker.AsyncResult(curr_at.ident)
if aresult:
curr_at.status = aresult.status
if curr_at.status == 'FAILURE':
result = aresult.get(timeout=2)
curr_at.error = str(result)
if not curr_at.error:
curr_at.error = result.__class__.__name__
self._check_task_timeout(curr_at)
return True
else:
logging.getLogger(__name__).warning(f'Background job not found: {curr_at.ident}')
return False
worker = bgcalc.calc_backend_client(settings)
aresult = worker.AsyncResult(curr_at.ident)
if aresult:
curr_at.status = aresult.status
if curr_at.status == 'FAILURE':
result = aresult.get(timeout=2)
curr_at.error = str(result)
if not curr_at.error:
curr_at.error = result.__class__.__name__
self._check_task_timeout(curr_at)
return True
else:
raise FunctionNotSupported(f'Backend {backend} does not support status checking')
logging.getLogger(__name__).warning(f'Background job not found: {curr_at.ident}')
return False

async def get_async_tasks(
self,
Expand Down
8 changes: 7 additions & 1 deletion lib/views/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ async def root_action(amodel: BaseActionModel, req: KRequest, resp: KResponse):


async def _check_task_status(amodel: UserActionModel, task_id: str) -> Optional[AsyncTaskStatus]:
task = AsyncTaskStatus(ident=task_id, label='', status='PENDING', category='')
task = None
for t in (await amodel.get_async_tasks()):
if t.ident == task_id:
task = t
break
if task is None: # not found but it can still be present on worker; TODO problem is, not all attrs will be preserved
task = AsyncTaskStatus(ident=task_id, label='', status='PENDING', category='')
found = await amodel.update_async_task_status(task)
return task if found else None

Expand Down
3 changes: 2 additions & 1 deletion public/files/js/views/keywords/result/style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ export const KeywordsResult = styled.form`
display: grid;
grid-template-columns: auto 1fr;
grid-column-gap: 0.7em;
align-items: center;
dd {
margin-inline-start: 0;
font-weight: bold;
font-size: 1.2em;
font-size: 1.1em;
}
}
Expand Down

0 comments on commit 6dd8baf

Please sign in to comment.