From d671e65bde10a92b58d40a50229ec28a5a75ee69 Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Thu, 1 Jul 2021 15:01:22 +0200 Subject: [CODESEARCH] Add option to define custom polling interval The default polling interval is set to 1h. Refreshing too often might result in too many requests in time and a remote service disruption or denial of access for client (too many requests) Change-Id: I490792ddedeb7a2c13f1bbb0f11ec68ed8fc2d5b Issue-ID: INT-1942 Signed-off-by: Bartek Grzybowski --- bootstrap/codesearch/create_config.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'bootstrap') diff --git a/bootstrap/codesearch/create_config.py b/bootstrap/codesearch/create_config.py index 6d72f1725..4ff059d19 100755 --- a/bootstrap/codesearch/create_config.py +++ b/bootstrap/codesearch/create_config.py @@ -18,6 +18,7 @@ CODE_LOCATION = "{path}{anchor}" GITWEB_ANCHOR = "#l{line}" GIT_ANCHOR = "#n{line}" +DEFAULT_POLL = 3600 def get_projects_list(gerrit): """Request list of all available projects from ONAP Gerrit.""" @@ -31,7 +32,7 @@ def get_projects_list(gerrit): return projects.keys() -def create_repos_list(projects, gerrit, ssh, git): +def create_repos_list(projects, gerrit, ssh, git, poll): """Create a map of all projects to their repositories' URLs.""" gerrit_url = "https://{}{}".format(gerrit, API_PREFIX) gerrit_project_url_base = "{}/{{}}.git".format(gerrit_url) @@ -54,7 +55,8 @@ def create_repos_list(projects, gerrit, ssh, git): "url": project_url, "url-pattern": { "base-url": code_url, - "anchor": anchor + "anchor": anchor, + "ms-between-poll": poll * 1000 } } @@ -67,6 +69,7 @@ def parse_arguments(): parser.add_argument('--gerrit', help='Gerrit address', default=DEFAULT_GERRIT) parser.add_argument('--ssh', help='SSH information: user, port', nargs=2) parser.add_argument('--git', help='external git address') + parser.add_argument('--poll-interval', help='repositories polling interval in seconds', type=int, default=DEFAULT_POLL) return parser.parse_args() @@ -76,7 +79,7 @@ def main(): arguments = parse_arguments() projects = get_projects_list(arguments.gerrit) - repos = create_repos_list(projects, arguments.gerrit, arguments.ssh, arguments.git) + repos = create_repos_list(projects, arguments.gerrit, arguments.ssh, arguments.git, arguments.poll_interval) config = { "max-concurrent-indexers": 2, "dbpath": "data", -- cgit 1.2.3-korg