Show More
@@ -29,6 +29,7 b' from rhodecode.api.utils import (' | |||
|
29 | 29 | get_user_group_or_error, get_user_or_error, validate_repo_permissions, |
|
30 | 30 | get_perm_or_error, parse_args, get_origin, build_commit_data, |
|
31 | 31 | validate_set_owner_permissions) |
|
32 | from rhodecode.lib import repo_maintenance | |
|
32 | 33 | from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi |
|
33 | 34 | from rhodecode.lib.utils2 import str2bool, time_to_datetime |
|
34 | 35 | from rhodecode.lib.ext_json import json |
@@ -1986,3 +1987,65 b' def set_repo_settings(request, apiuser, ' | |||
|
1986 | 1987 | |
|
1987 | 1988 | # Indicate success. |
|
1988 | 1989 | return True |
|
1990 | ||
|
1991 | ||
|
1992 | @jsonrpc_method() | |
|
1993 | def maintenance(request, apiuser, repoid): | |
|
1994 | """ | |
|
1995 | Triggers a maintenance on the given repository. | |
|
1996 | ||
|
1997 | This command can only be run using an |authtoken| with admin | |
|
1998 | rights to the specified repository. For more information, | |
|
1999 | see :ref:`config-token-ref`. | |
|
2000 | ||
|
2001 | This command takes the following options: | |
|
2002 | ||
|
2003 | :param apiuser: This is filled automatically from the |authtoken|. | |
|
2004 | :type apiuser: AuthUser | |
|
2005 | :param repoid: The repository name or repository ID. | |
|
2006 | :type repoid: str or int | |
|
2007 | ||
|
2008 | Example output: | |
|
2009 | ||
|
2010 | .. code-block:: bash | |
|
2011 | ||
|
2012 | id : <id_given_in_input> | |
|
2013 | result : { | |
|
2014 | "msg": "executed maintenance command", | |
|
2015 | "executed_actions": [ | |
|
2016 | <action_message>, <action_message2>... | |
|
2017 | ], | |
|
2018 | "repository": "<repository name>" | |
|
2019 | } | |
|
2020 | error : null | |
|
2021 | ||
|
2022 | Example error output: | |
|
2023 | ||
|
2024 | .. code-block:: bash | |
|
2025 | ||
|
2026 | id : <id_given_in_input> | |
|
2027 | result : null | |
|
2028 | error : { | |
|
2029 | "Unable to execute maintenance on `<reponame>`" | |
|
2030 | } | |
|
2031 | ||
|
2032 | """ | |
|
2033 | ||
|
2034 | repo = get_repo_or_error(repoid) | |
|
2035 | if not has_superadmin_permission(apiuser): | |
|
2036 | _perms = ('repository.admin',) | |
|
2037 | validate_repo_permissions(apiuser, repoid, repo, _perms) | |
|
2038 | ||
|
2039 | try: | |
|
2040 | maintenance = repo_maintenance.RepoMaintenance() | |
|
2041 | executed_actions = maintenance.execute(repo) | |
|
2042 | ||
|
2043 | return { | |
|
2044 | 'msg': 'executed maintenance command', | |
|
2045 | 'executed_actions': executed_actions, | |
|
2046 | 'repository': repo.repo_name | |
|
2047 | } | |
|
2048 | except Exception: | |
|
2049 | log.exception("Exception occurred while trying to run maintenance") | |
|
2050 | raise JSONRPCError( | |
|
2051 | 'Unable to execute maintenance on `%s`' % repo.repo_name) |
@@ -4,18 +4,26 b'' | |||
|
4 | 4 | </div> |
|
5 | 5 | <div class="panel-body"> |
|
6 | 6 | |
|
7 | <p> | |
|
8 | 7 |
|
|
9 |
|
|
|
8 | <h4>${_('Perform maintenance tasks for this repo')}</h4> | |
|
9 | ||
|
10 | <span>${_('Following tasks will be performed')}:</span> | |
|
10 | 11 |
|
|
11 | 12 |
|
|
12 | 13 |
|
|
13 | 14 |
|
|
14 | 15 |
|
|
16 | <p> | |
|
17 | ${_('Maintenance can be automated by such api call. Can be called periodically in crontab etc.')} | |
|
18 | <br/> | |
|
19 | <code> | |
|
20 | ${h.api_call_example(method='maintenance', args={"repoid": c.repo_info.repo_name})} | |
|
21 | </code> | |
|
22 | </p> | |
|
23 | ||
|
15 | 24 |
|
|
16 |
|
|
|
25 | <h4>${_('No maintenance tasks for this repo available')}</h4> | |
|
17 | 26 |
|
|
18 | </p> | |
|
19 | 27 | |
|
20 | 28 | <div id="results" style="display:none; padding: 10px 0px;"></div> |
|
21 | 29 |
General Comments 0
You need to be logged in to leave comments.
Login now