cgit/tasks: Allow passing extra parameters to task

This unifies with other lister tasks modules. And this allow the cgit task to
be scheduled by the add-forge-now scheduler cli.

Refs. swh/infra/sysadm-environment#4813
This commit is contained in:
Antoine R. Dumont (@ardumont) 2023-03-21 12:22:07 +01:00
parent 571d69f965
commit 45bbc29a52
No known key found for this signature in database
GPG key ID: 52E2E9840D10C3B8
2 changed files with 8 additions and 10 deletions

View file

@ -1,8 +1,8 @@
# Copyright (C) 2019-2021 The Software Heritage developers
# Copyright (C) 2019 The Software Heritage developers
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from typing import Dict, Optional
from typing import Dict
from celery import shared_task
@ -10,13 +10,9 @@ from .lister import CGitLister
@shared_task(name=__name__ + ".CGitListerTask")
def list_cgit(
url: str, instance: Optional[str] = None, base_git_url: Optional[str] = None
) -> Dict[str, str]:
def list_cgit(**lister_args) -> Dict[str, str]:
"""Lister task for CGit instances"""
lister = CGitLister.from_configfile(
url=url, instance=instance, base_git_url=base_git_url
)
lister = CGitLister.from_configfile(**lister_args)
return lister.run().dict()

View file

@ -1,4 +1,4 @@
# Copyright (C) 2019-2021 The Software Heritage developers
# Copyright (C) 2019 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
@ -22,7 +22,9 @@ def test_cgit_lister_task(
lister.from_configfile.return_value = lister
lister.run.return_value = ListerStats(pages=10, origins=500)
kwargs = dict(url="https://git.kernel.org/", instance="kernel", base_git_url=None)
kwargs = dict(
url="https://git.kernel.org/", instance="kernel", base_git_url=None, max_pages=1
)
res = swh_scheduler_celery_app.send_task(
"swh.lister.cgit.tasks.CGitListerTask",