-
Notifications
You must be signed in to change notification settings - Fork 32
🎨 Add removal of project documents from the Redis (Garbage Collection background task) #8177
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
Merged
matusdrobuliak66
merged 28 commits into
ITISFoundation:master
from
matusdrobuliak66:is1647/collaboration-features-3
Jul 31, 2025
Merged
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
b2d3396
Adds client session ID propagation for user actions
matusdrobuliak66 92cb19f
Merge branch 'master' into is1647/collaboration-features-2
matusdrobuliak66 8c5b95d
Removes unused frontend outputs update logic
matusdrobuliak66 a68c91e
fix tests
matusdrobuliak66 4d3d978
Refactors project document update for clarity and atomicity
matusdrobuliak66 503ef0f
fix tests
matusdrobuliak66 f58843c
Merge branch 'master' into is1647/collaboration-features-2
matusdrobuliak66 ae5be6f
review @sanderegg
matusdrobuliak66 0d5a6c3
review @sanderegg @pcrespov
matusdrobuliak66 89a9394
review @pcrespov
matusdrobuliak66 ac80fed
fix
matusdrobuliak66 26ac23b
fix
matusdrobuliak66 0b8c698
fix
matusdrobuliak66 e4b4a0b
additional tests
matusdrobuliak66 22cae1b
Adds periodic cleanup task for project documents
matusdrobuliak66 04110d4
Removes project documents with no active users
matusdrobuliak66 ed21eb0
Refactors project document cleanup to use shared registry utility
matusdrobuliak66 b07870a
additional tests
matusdrobuliak66 ff0062f
Refactors project document removal unit tests with fixtures
matusdrobuliak66 998ff14
additional tests
matusdrobuliak66 76d70e0
fix mypy
matusdrobuliak66 32b0db0
Merge branch 'master' into is1647/collaboration-features-3
matusdrobuliak66 4653951
add GARBAGE_COLLECTOR_PRUNE_DOCUMENTS_INTERVAL_S
matusdrobuliak66 a8ee4d9
Merge branch 'master' into is1647/collaboration-features-3
matusdrobuliak66 05bfe3e
review @sanderegg @pcrespov
matusdrobuliak66 88402f5
review @pcrespov
matusdrobuliak66 b3d1213
review @pcrespov
matusdrobuliak66 94c1cdc
review @sanderegg
matusdrobuliak66 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
services/web/server/src/simcore_service_webserver/garbage_collector/_tasks_documents.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """ | ||
| Scheduled tasks addressing users | ||
|
|
||
| """ | ||
|
|
||
| import logging | ||
| from collections.abc import AsyncIterator | ||
| from datetime import timedelta | ||
|
|
||
| from aiohttp import web | ||
| from servicelib.background_task_utils import exclusive_periodic | ||
| from servicelib.logging_utils import log_context | ||
|
|
||
| from ..projects import projects_documents_service | ||
| from ..redis import get_redis_lock_manager_client_sdk | ||
| from ._tasks_utils import CleanupContextFunc, periodic_task_lifespan | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def create_background_task_to_prune_documents(wait_s: float) -> CleanupContextFunc: | ||
|
|
||
| async def _cleanup_ctx_fun(app: web.Application) -> AsyncIterator[None]: | ||
| interval = timedelta(seconds=wait_s) | ||
|
|
||
| @exclusive_periodic( | ||
| # Function-exclusiveness is required to avoid multiple tasks like thisone running concurrently | ||
| get_redis_lock_manager_client_sdk(app), | ||
| task_interval=interval, | ||
| retry_after=min(timedelta(seconds=10), interval / 10), | ||
| ) | ||
| async def _prune_documents_periodically() -> None: | ||
| with log_context( | ||
| _logger, | ||
| logging.INFO, | ||
| "Deleting project documents in Redis `documents` table started", | ||
| ): | ||
| await projects_documents_service.remove_project_documents_as_admin(app) | ||
|
|
||
| async for _ in periodic_task_lifespan(app, _prune_documents_periodically): | ||
| yield | ||
|
|
||
| return _cleanup_ctx_fun |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
services/web/server/src/simcore_service_webserver/projects/projects_documents_service.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from ._project_document_service import ( | ||
| remove_project_documents_as_admin, | ||
| ) | ||
|
|
||
| __all__: tuple[str, ...] = ("remove_project_documents_as_admin",) | ||
|
|
||
|
|
||
| # nopycln: file |
18 changes: 18 additions & 0 deletions
18
services/web/server/src/simcore_service_webserver/resource_manager/registry_utils.py
matusdrobuliak66 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import logging | ||
|
|
||
| from models_library.projects import ProjectID | ||
|
|
||
| from .registry import RedisResourceRegistry | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def list_opened_project_ids(registry: RedisResourceRegistry) -> list[ProjectID]: | ||
| """Lists all project IDs that are currently opened in active sessions.""" | ||
| opened_projects: list[ProjectID] = [] | ||
| all_session_alive, _ = await registry.get_all_resource_keys() | ||
| for alive_session in all_session_alive: | ||
| resources = await registry.get_resources(alive_session) | ||
| if "project_id" in resources: | ||
matusdrobuliak66 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| opened_projects.append(ProjectID(resources["project_id"])) | ||
| return opened_projects | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.