Skip to content

Commit

Permalink
Add support for background updates status
Browse files Browse the repository at this point in the history
  • Loading branch information
KnugiHK committed Nov 14, 2021
1 parent 3d04563 commit c9111ad
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
7 changes: 1 addition & 6 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@ This document describes what need to be changed or added due to the changes made
1. More tests for CI

## Synapse
### 1.46.0
1. Users admin API can now also modify user type in addition to allowing it to be set on user creation. ([#11174](https://github.com/matrix-org/synapse/issues/11174))

### 1.47.0
1. Add search by room ID and room alias to the List Room admin API. ([#11099](https://github.com/matrix-org/synapse/issues/11099))
2. Add admin APIs to pause, start and check the status of background updates. ([#11263](https://github.com/matrix-org/synapse/issues/11263))
1. Add admin APIs to pause, start and check the status of background updates. ([#11263](https://github.com/matrix-org/synapse/issues/11263)) -> Test needed
42 changes: 42 additions & 0 deletions synapse_admin/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,45 @@ def delete_group(self, groupid: str) -> bool:
return False, data["errcode"], data["error"]
else:
raise SynapseException(data["errcode"], data["error"])

def background_updates_get(self) -> dict:
"""Get the current status of background updates
Returns:
dict: a dict with all current_updates
"""
resp = self.connection.request(
"GET",
self.admin_patterns("/background_updates/status", 1)
)
data = resp.json()
if resp.status_code == 200:
return data
else:
if self.suppress_exception:
return False, data["errcode"], data["error"]
else:
raise SynapseException(data["errcode"], data["error"])

def background_updates_set(self, enabled: bool) -> bool:
"""Pause or resume background updates
Args:
enabled (bool, optional): True to enable, False to disable background updates. # noqa: E501
Returns:
bool: whether the background updates are now enabled or disabled. True means enabled, False means disabled.
"""
resp = self.connection.request(
"POST",
self.admin_patterns("/background_updates/enabled", 1),
json={"enabled": enabled}
)
data = resp.json()
if resp.status_code == 200:
return data["enabled"]
else:
if self.suppress_exception:
return False, data["errcode"], data["error"]
else:
raise SynapseException(data["errcode"], data["error"])
6 changes: 6 additions & 0 deletions tests/test_2_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,9 @@ def test_management_delete_group():
).status_code == 404
with pytest.raises(SynapseException):
mgt_handler.delete_group("+invalid:localhost")

def test_management_background_updates_get():
...

def test_management_background_updates_set():
...

0 comments on commit c9111ad

Please sign in to comment.