tasks: normalize the url argument name of most lister
Since all the listing tasks accepts an url as first argument (whatever the argument name is), it makes sense to use a simple common argument name for this. I've chosen 'url' instead of api_baseurl/forge_url/url. Also kill now useless `new_lister()` functions.
This commit is contained in:
parent
631b8e7668
commit
b810876ef8
19 changed files with 60 additions and 91 deletions
|
@ -16,12 +16,11 @@ class GitLabLister(PageByPageHttpLister):
|
|||
MODEL = GitLabModel
|
||||
LISTER_NAME = 'gitlab'
|
||||
|
||||
def __init__(self, api_baseurl=None, instance=None,
|
||||
def __init__(self, url=None, instance=None,
|
||||
override_config=None, sort='asc', per_page=20):
|
||||
super().__init__(api_baseurl=api_baseurl,
|
||||
override_config=override_config)
|
||||
super().__init__(url=url, override_config=override_config)
|
||||
if instance is None:
|
||||
instance = parse_url(self.api_baseurl).host
|
||||
instance = parse_url(self.url).host
|
||||
self.instance = instance
|
||||
self.PATH_TEMPLATE = '%s&sort=%s&per_page=%s' % (
|
||||
self.PATH_TEMPLATE, sort, per_page)
|
||||
|
|
|
@ -14,18 +14,11 @@ from .lister import GitLabLister
|
|||
NBPAGES = 10
|
||||
|
||||
|
||||
def new_lister(api_baseurl='https://gitlab.com/api/v4',
|
||||
instance=None, sort='asc', per_page=20):
|
||||
return GitLabLister(
|
||||
api_baseurl=api_baseurl, instance=instance, sort=sort,
|
||||
per_page=per_page)
|
||||
|
||||
|
||||
@app.task(name=__name__ + '.IncrementalGitLabLister')
|
||||
def list_gitlab_incremental(**lister_args):
|
||||
"""Incremental update of a GitLab instance"""
|
||||
lister_args['sort'] = 'desc'
|
||||
lister = new_lister(**lister_args)
|
||||
lister = GitLabLister(**lister_args)
|
||||
total_pages = lister.get_pages_information()[1]
|
||||
# stopping as soon as existing origins for that instance are detected
|
||||
lister.run(min_bound=1, max_bound=total_pages, check_existence=True)
|
||||
|
@ -33,14 +26,14 @@ def list_gitlab_incremental(**lister_args):
|
|||
|
||||
@app.task(name=__name__ + '.RangeGitLabLister')
|
||||
def _range_gitlab_lister(start, end, **lister_args):
|
||||
lister = new_lister(**lister_args)
|
||||
lister = GitLabLister(**lister_args)
|
||||
lister.run(min_bound=start, max_bound=end)
|
||||
|
||||
|
||||
@app.task(name=__name__ + '.FullGitLabRelister', bind=True)
|
||||
def list_gitlab_full(self, **lister_args):
|
||||
"""Full update of a GitLab instance"""
|
||||
lister = new_lister(**lister_args)
|
||||
lister = GitLabLister(**lister_args)
|
||||
_, total_pages, _ = lister.get_pages_information()
|
||||
ranges = list(utils.split_range(total_pages, NBPAGES))
|
||||
random.shuffle(ranges)
|
||||
|
|
|
@ -26,9 +26,7 @@ def test_incremental(lister, swh_app, celery_session_worker):
|
|||
res.wait()
|
||||
assert res.successful()
|
||||
|
||||
lister.assert_called_once_with(
|
||||
api_baseurl='https://gitlab.com/api/v4',
|
||||
instance=None, sort='desc', per_page=20)
|
||||
lister.assert_called_once_with(sort='desc')
|
||||
lister.db_last_index.assert_not_called()
|
||||
lister.get_pages_information.assert_called_once_with()
|
||||
lister.run.assert_called_once_with(
|
||||
|
@ -48,9 +46,7 @@ def test_range(lister, swh_app, celery_session_worker):
|
|||
res.wait()
|
||||
assert res.successful()
|
||||
|
||||
lister.assert_called_once_with(
|
||||
api_baseurl='https://gitlab.com/api/v4',
|
||||
instance=None, sort='asc', per_page=20)
|
||||
lister.assert_called_once_with()
|
||||
lister.db_last_index.assert_not_called()
|
||||
lister.run.assert_called_once_with(min_bound=12, max_bound=42)
|
||||
|
||||
|
@ -81,9 +77,7 @@ def test_relister(lister, swh_app, celery_session_worker):
|
|||
break
|
||||
sleep(1)
|
||||
|
||||
lister.assert_called_with(
|
||||
api_baseurl='https://gitlab.com/api/v4',
|
||||
instance=None, sort='asc', per_page=20)
|
||||
lister.assert_called_with()
|
||||
|
||||
# one by the FullGitlabRelister task
|
||||
# + 9 for the RangeGitlabLister subtasks
|
||||
|
@ -113,7 +107,7 @@ def test_relister_instance(lister, swh_app, celery_session_worker):
|
|||
|
||||
res = swh_app.send_task(
|
||||
'swh.lister.gitlab.tasks.FullGitLabRelister',
|
||||
kwargs=dict(api_baseurl='https://0xacab.org/api/v4'))
|
||||
kwargs=dict(url='https://0xacab.org/api/v4'))
|
||||
assert res
|
||||
|
||||
res.wait()
|
||||
|
@ -129,9 +123,7 @@ def test_relister_instance(lister, swh_app, celery_session_worker):
|
|||
break
|
||||
sleep(1)
|
||||
|
||||
lister.assert_called_with(
|
||||
api_baseurl='https://0xacab.org/api/v4',
|
||||
instance=None, sort='asc', per_page=20)
|
||||
lister.assert_called_with(url='https://0xacab.org/api/v4')
|
||||
|
||||
# one by the FullGitlabRelister task
|
||||
# + 9 for the RangeGitlabLister subtasks
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue