swh.lister.gitlab: Add Incremental lister behavior
Related T989
This commit is contained in:
parent
ccd0525c9b
commit
847a8d341a
3 changed files with 43 additions and 4 deletions
|
@ -12,7 +12,7 @@ from .models import GitLabModel
|
|||
|
||||
class GitLabLister(PageByPageHttpLister):
|
||||
# Template path expecting an integer that represents the page id
|
||||
PATH_TEMPLATE = '/projects?page=%d&order_by=id&sort=asc&simple=true'
|
||||
PATH_TEMPLATE = '/projects?page=%d&order_by=id'
|
||||
API_URL_INDEX_RE = re.compile(r'^.*/projects.*page=(\d+).*')
|
||||
MODEL = GitLabModel
|
||||
LISTER_NAME = 'gitlab'
|
||||
|
@ -103,7 +103,7 @@ class GitLabLister(PageByPageHttpLister):
|
|||
return None
|
||||
|
||||
def get_pages_information(self):
|
||||
"""Determine some pages information.
|
||||
"""Determine pages information.
|
||||
|
||||
"""
|
||||
response = self.transport_head(identifier=1)
|
||||
|
|
|
@ -17,13 +17,16 @@ class GitLabListerTask(ListerTaskBase):
|
|||
|
||||
|
||||
class RangeGitLabLister(GitLabListerTask, RangeListerTask):
|
||||
"""GitLab lister working on specified range (start, end) arguments.
|
||||
"""Range GitLab lister (list available origins on specified range)
|
||||
|
||||
"""
|
||||
task_queue = 'swh_lister_gitlab_refresh'
|
||||
|
||||
|
||||
class FullGitLabRelister(GitLabListerTask):
|
||||
"""Full GitLab lister (list all available origins from the api).
|
||||
|
||||
"""
|
||||
task_queue = 'swh_lister_gitlab_refresh'
|
||||
|
||||
def run_task(self, *args, **kwargs):
|
||||
|
@ -41,3 +44,22 @@ class FullGitLabRelister(GitLabListerTask):
|
|||
range_task = RangeGitLabLister()
|
||||
group(range_task.s(minv, maxv, *args, **kwargs)
|
||||
for minv, maxv in ranges)()
|
||||
|
||||
|
||||
class IncrementalGitLabLister(ListerTaskBase):
|
||||
"""Incremental GitLab lister (list only new available origins).
|
||||
|
||||
"""
|
||||
task_queue = 'swh_lister_gitlab_discover'
|
||||
|
||||
def new_lister(self, api_baseurl='https://gitlab.com/api/v4',
|
||||
instance='gitlab.com',):
|
||||
# will invert the order of the lister's result
|
||||
return GitLabLister(instance=instance, api_baseurl=api_baseurl,
|
||||
sort='desc')
|
||||
|
||||
def run_task(self, *args, **kwargs):
|
||||
lister = self.new_lister(*args, **kwargs)
|
||||
# will check for existing data and exit when found
|
||||
return lister.run(min_bound=None, max_bound=None,
|
||||
check_existence=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue