core: avoid using rhodecode.test packages inside main packages as tests are removed during build which can cause some problems in some edge case calls

This commit is contained in:
RhodeCode Admin 2024-11-13 09:49:39 +01:00
parent b6b0974b8c
commit 2b623ea7f2
5 changed files with 106 additions and 38 deletions

View file

@ -213,6 +213,62 @@ def rescan_repos(request, apiuser, remove_obsolete=Optional(False)):
'Error occurred during rescan repositories action'
)
@jsonrpc_method()
def cleanup_repos(request, apiuser, remove_obsolete=Optional(False)):
"""
Triggers a rescan of the specified repositories.
* If the ``remove_obsolete`` option is set, it also deletes repositories
that are found in the database but not on the file system, so called
"clean zombies".
This command can only be run using an |authtoken| with admin rights to
the specified repository.
This command takes the following options:
:param apiuser: This is filled automatically from the |authtoken|.
:type apiuser: AuthUser
:param remove_obsolete: Deletes repositories from the database that
are not found on the filesystem.
:type remove_obsolete: Optional(``True`` | ``False``)
Example output:
.. code-block:: bash
id : <id_given_in_input>
result : {
'added': [<added repository name>,...]
'removed': [<removed repository name>,...]
}
error : null
Example error output:
.. code-block:: bash
id : <id_given_in_input>
result : null
error : {
'Error occurred during rescan repositories action'
}
"""
if not has_superadmin_permission(apiuser):
raise JSONRPCForbidden()
try:
rm_obsolete = Optional.extract(remove_obsolete)
added, removed = repo2db_mapper(ScmModel().repo_scan(),
remove_obsolete=rm_obsolete, force_hooks_rebuild=True)
return {'added': added, 'removed': removed}
except Exception:
log.exception('Failed to run repo rescann')
raise JSONRPCError(
'Error occurred during rescan repositories action'
)
@jsonrpc_method()
def cleanup_sessions(request, apiuser, older_then=Optional(60)):