This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Delete device messages asynchronously and in staged batches #16240
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
599aa4e
Delete device messages asynchronously and in staged batches
d891de8
Add changelog
0246703
Fix init circular dep
b003fb6
Fix
82908f6
typo
45b6be2
Please postgres
c496729
Do better
ce486b2
Update synapse/storage/databases/main/deviceinbox.py
6f080c2
Merge branch 'develop' into mv/async-batched-delete-to-devices
61f2c54
Address review comments
76fab72
Typo
1ebfacc
Simplify
c39dcde
Move function check for task scheduler
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Delete device messages asynchronously and in staged batches using the task scheduler. |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,7 @@ class TaskScheduler: | |
| LAST_UPDATE_BEFORE_WARNING_MS = 24 * 60 * 60 * 1000 # 24hrs | ||
|
|
||
| def __init__(self, hs: "HomeServer"): | ||
| self._hs = hs | ||
| self._store = hs.get_datastores().main | ||
| self._clock = hs.get_clock() | ||
| self._running_tasks: Set[str] = set() | ||
|
|
@@ -97,8 +98,6 @@ def __init__(self, hs: "HomeServer"): | |
| "handle_scheduled_tasks", | ||
| self._handle_scheduled_tasks, | ||
| ) | ||
| else: | ||
| self.replication_client = hs.get_replication_command_handler() | ||
MatMaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def register_action( | ||
| self, | ||
|
|
@@ -133,7 +132,7 @@ async def schedule_task( | |
| params: Optional[JsonMapping] = None, | ||
| ) -> str: | ||
| """Schedule a new potentially resumable task. A function matching the specified | ||
| `action` should have been previously registered with `register_action`. | ||
| `action` should have be registered with `register_action` before the task is run. | ||
|
|
||
| Args: | ||
| action: the name of a previously registered action | ||
|
|
@@ -149,11 +148,6 @@ async def schedule_task( | |
| Returns: | ||
| The id of the scheduled task | ||
| """ | ||
| if action not in self._actions: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is moved inside |
||
| raise Exception( | ||
| f"No function associated with action {action} of the scheduled task" | ||
| ) | ||
|
|
||
| status = TaskStatus.SCHEDULED | ||
| if timestamp is None or timestamp < self._clock.time_msec(): | ||
| timestamp = self._clock.time_msec() | ||
|
|
@@ -175,7 +169,7 @@ async def schedule_task( | |
| if self._run_background_tasks: | ||
| await self._launch_task(task) | ||
| else: | ||
| self.replication_client.send_new_active_task(task.id) | ||
| self._hs.get_replication_command_handler().send_new_active_task(task.id) | ||
|
|
||
| return task.id | ||
|
|
||
|
|
@@ -315,7 +309,10 @@ async def _launch_task(self, task: ScheduledTask) -> None: | |
| """ | ||
| assert self._run_background_tasks | ||
|
|
||
| assert task.action in self._actions | ||
| if task.action not in self._actions: | ||
| raise Exception( | ||
| f"No function associated with action {task.action} of the scheduled task {task.id}" | ||
| ) | ||
| function = self._actions[task.action] | ||
|
|
||
| async def wrapper() -> None: | ||
|
|
||
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.