Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Long running tasks: allow retrieving tasks by user #3268

Conversation

sanderegg
Copy link
Member

@sanderegg sanderegg commented Aug 16, 2022

What do these changes do?

This is a pre-requisite so that the frontend may retrieve currently running project copy tasks after a refresh or a snap (will need @odeimaiz to modify the frontend accordingly).

long running tasks framework:

  • implementation of listing of tasks (aiohttp/fastapi)
  • modified all tasks routes to take care of the "task context" (like a user_id), only in aiohttp
  • a task context can be defined (such as in the webserver something like {user_id: 123, product: osparc}, then every task route will filter with that task context (e.g. user 1 cannot see the tasks of user 3, user 1 can only cancel his/her own tasks)
  • simplified and refactored testing (both aiohttp/fastapi)

webserver

  • adds GET /tasks in the webserver REST API, which returns the list of currently running async tasks in the webserver for a specific user_id (through the usual logged in user facility): return the list of tasks of the user in the form of POST /v0/projects?from_study=de2578c5-431e-6257-a462-d7bf73b76c0c
  • added test to check that one user cannot access another user tasks
  • allow setting a task name so the frontend may retrieve the user tasks (task name is set as "METHOD path")

Related issue/s

related to ITISFoundation/osparc-issues#428

How to test

cd packages/service-lib
make "install-dev[all]"
make "test-dev[all]"

cd services/web/server
make install-dev
clear && pytest -vvx --pdb --color=yes --asyncio-mode=auto --ff --cov-config=../../../.coveragerc --cov-report=term-missing --cov=servicelib --keep-docker-up tests/unit/with_dbs/02/te

Checklist

@sanderegg sanderegg added this to the Brutalism milestone Aug 16, 2022
@sanderegg sanderegg self-assigned this Aug 16, 2022
@codecov
Copy link

codecov bot commented Aug 16, 2022

Codecov Report

Merging #3268 (b3939e8) into master (38b6073) will increase coverage by 1.0%.
The diff coverage is 94.9%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #3268     +/-   ##
========================================
+ Coverage    82.3%   83.3%   +1.0%     
========================================
  Files         755     682     -73     
  Lines       32249   30025   -2224     
  Branches     4121    3829    -292     
========================================
- Hits        26549   25028   -1521     
+ Misses       4859    4214    -645     
+ Partials      841     783     -58     
Flag Coverage Δ
integrationtests 66.3% <75.0%> (+<0.1%) ⬆️
unittests 79.5% <94.9%> (+0.7%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...namic_sidecar/api/containers_long_running_tasks.py 100.0% <ø> (ø)
...rvice_webserver/projects/projects_handlers_crud.py 87.4% <75.0%> (-0.8%) ⬇️
...vice_dynamic_sidecar/modules/long_running_tasks.py 90.2% <100.0%> (ø)
...erver/src/simcore_service_webserver/application.py 98.8% <100.0%> (ø)
...rc/simcore_service_webserver/long_running_tasks.py 100.0% <100.0%> (ø)
...mcore_service_webserver/garbage_collector_utils.py 82.0% <0.0%> (-2.6%) ⬇️
...ector_v2/modules/dynamic_sidecar/scheduler/task.py 81.1% <0.0%> (-1.3%) ⬇️
.../director/src/simcore_service_director/producer.py 61.6% <0.0%> (-0.5%) ⬇️
...imcore_service_webserver/garbage_collector_core.py 71.0% <0.0%> (ø)
...ervicelib/aiohttp/long_running_tasks/_constants.py
... and 76 more

@sanderegg sanderegg force-pushed the enhancement/retrieve_long_running_tasks branch 5 times, most recently from 2e4096e to d18b721 Compare August 22, 2022 16:17
@sanderegg sanderegg marked this pull request as ready for review August 23, 2022 08:30
@sanderegg sanderegg force-pushed the enhancement/retrieve_long_running_tasks branch from e1f89d7 to 0f4b885 Compare August 23, 2022 08:38
Copy link
Member

@pcrespov pcrespov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!
Some minor comments and thoughts below



def get_tasks_manager(app: web.Application) -> TasksManager:
return app[APP_LONG_RUNNING_TASKS_MANAGER_KEY]


def get_task_context(request: web.Request) -> dict[str, Any]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

STYLE: the word task might refer to different concepts. I suggest that we denote these as long_running_tasks or long_tasks or lgr_tasks ... or something similar.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this not a bit exagerated? this lives in a module named long_running_tasks already. and everything in here talks about tasks. I do agree with that fact.
I will think of it for a different PR.
I could also think of renaming the module package into something like rest_async_task instead of long running... since what is long?

@@ -139,6 +141,8 @@ async def create_projects(request: web.Request):
query_params=query_params,
user_id=req_ctx.user_id,
predefined_project=predefined_project,
task_context=jsonable_encoder(req_ctx),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so here the lrtask context is decided to be exactly as the request context. Is it always the case?

THOUGHT:
if so, perhaps we need to store the request (storage) always instead of defining a new task_context...
AFAIK you want to keep track of the "original" request that triggered the lrtask, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but how do I know what needs to be taken out of the request?

@sanderegg sanderegg force-pushed the enhancement/retrieve_long_running_tasks branch from 0f4b885 to 6f83874 Compare August 23, 2022 12:15
@sanderegg sanderegg force-pushed the enhancement/retrieve_long_running_tasks branch from ee7b24b to b3939e8 Compare August 24, 2022 19:39
@sonarcloud
Copy link

sonarcloud bot commented Aug 24, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@sanderegg sanderegg merged commit 72ac74d into ITISFoundation:master Aug 24, 2022
@sanderegg sanderegg deleted the enhancement/retrieve_long_running_tasks branch August 24, 2022 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants