[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 <b.grzybowski@partner.samsung.com>
diff --git a/bootstrap/codesearch/create_config.py b/bootstrap/codesearch/create_config.py
index 6d72f17..4ff059d 100755
--- a/bootstrap/codesearch/create_config.py
+++ b/bootstrap/codesearch/create_config.py
@@ -18,6 +18,7 @@
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 @@
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 @@
"url": project_url,
"url-pattern": {
"base-url": code_url,
- "anchor": anchor
+ "anchor": anchor,
+ "ms-between-poll": poll * 1000
}
}
@@ -67,6 +69,7 @@
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 @@
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",