diff --git a/swh/web/common/management/commands/refresh_savecodenow_statuses.py b/swh/web/common/management/commands/refresh_savecodenow_statuses.py --- a/swh/web/common/management/commands/refresh_savecodenow_statuses.py +++ b/swh/web/common/management/commands/refresh_savecodenow_statuses.py @@ -5,14 +5,44 @@ from django.core.management.base import BaseCommand +from swh.scheduler.model import ListedOrigin from swh.web.common.origin_save import refresh_save_origin_request_statuses +from swh.web.config import scheduler as get_scheduler class Command(BaseCommand): help = "Refresh save code now origin request statuses periodically" def handle(self, *args, **options): + """Refresh origin save code now requests. For the origin visit types, svn, git, hg, this + also installs the origins as recurring origins to visit. + + """ refreshed_statuses = refresh_save_origin_request_statuses() + scheduler = get_scheduler() + + # then schedule the origins with meaningful status and type to be ingested + # regularly + lister = scheduler.get_or_create_lister( + name="save-code-now", instance_name="host" + ) + + listed_origins = [] + for status in refreshed_statuses: + visit_type = status["visit_type"] + visit_status = status["visit_status"] + if visit_type == "archives": # only deal with git, svn, hg + continue + if visit_status not in ("partial", "full"): + continue + listed_origins.append( + ListedOrigin( + lister_id=lister.id, visit_type=visit_type, url=status["origin_url"] + ) + ) + + if listed_origins: + scheduler.record_listed_origins([listed_origins]) if len(refreshed_statuses) > 0: msg = f"Successfully updated {len(refreshed_statuses)} save request(s)."