##// END OF EJS Templates
api: added maintenance command into API.
marcink -
r1742:1fa46212 default
parent child Browse files
Show More
@@ -29,6 +29,7 b' from rhodecode.api.utils import ('
29 get_user_group_or_error, get_user_or_error, validate_repo_permissions,
29 get_user_group_or_error, get_user_or_error, validate_repo_permissions,
30 get_perm_or_error, parse_args, get_origin, build_commit_data,
30 get_perm_or_error, parse_args, get_origin, build_commit_data,
31 validate_set_owner_permissions)
31 validate_set_owner_permissions)
32 from rhodecode.lib import repo_maintenance
32 from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi
33 from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi
33 from rhodecode.lib.utils2 import str2bool, time_to_datetime
34 from rhodecode.lib.utils2 import str2bool, time_to_datetime
34 from rhodecode.lib.ext_json import json
35 from rhodecode.lib.ext_json import json
@@ -1986,3 +1987,65 b' def set_repo_settings(request, apiuser, '
1986
1987
1987 # Indicate success.
1988 # Indicate success.
1988 return True
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,19 +4,27 b''
4 </div>
4 </div>
5 <div class="panel-body">
5 <div class="panel-body">
6
6
7 % if c.executable_tasks:
8 <h4>${_('Perform maintenance tasks for this repo')}</h4>
9
10 <span>${_('Following tasks will be performed')}:</span>
11 <ol>
12 % for task in c.executable_tasks:
13 <li>${task}</li>
14 % endfor
15 </ol>
7 <p>
16 <p>
8 % if c.executable_tasks:
17 ${_('Maintenance can be automated by such api call. Can be called periodically in crontab etc.')}
9 ${_('Perform maintenance tasks for this repo, following tasks will be performed')}:
18 <br/>
10 <ol>
19 <code>
11 % for task in c.executable_tasks:
20 ${h.api_call_example(method='maintenance', args={"repoid": c.repo_info.repo_name})}
12 <li>${task}</li>
21 </code>
13 % endfor
14 </ol>
15 % else:
16 ${_('No maintenance tasks for this repo available')}
17 % endif
18 </p>
22 </p>
19
23
24 % else:
25 <h4>${_('No maintenance tasks for this repo available')}</h4>
26 % endif
27
20 <div id="results" style="display:none; padding: 10px 0px;"></div>
28 <div id="results" style="display:none; padding: 10px 0px;"></div>
21
29
22 % if c.executable_tasks:
30 % if c.executable_tasks:
General Comments 0
You need to be logged in to leave comments. Login now