Skip to content

Commit

Permalink
Make check-onboarded-projects a daily job (#2352)
Browse files Browse the repository at this point in the history
Make check-onboarded-projects a daily job

This should hopefully fix the long prefetch task queue in celery

Reviewed-by: Laura Barcziová
  • Loading branch information
softwarefactory-project-zuul[bot] authored Feb 16, 2024
2 parents bd38a84 + 679a0ff commit c1ab816
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 35 deletions.
5 changes: 5 additions & 0 deletions packit_service/celery_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"schedule": crontab(minute=0, hour=1), # nightly at 1AM
"options": {"queue": "long-running"},
},
"check-onboarded-projects": {
"task": "packit_service.worker.tasks.run_check_onboarded_projects",
"schedule": crontab(minute=0, hour=2), # nightly at 2AM
"options": {"queue": "long-running"},
},
}

# http://mher.github.io/flower/prometheus-integration.html#set-up-your-celery-application
Expand Down
22 changes: 0 additions & 22 deletions packit_service/service/api/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
SyncReleaseTargetModel,
)
from packit_service.service.api.utils import response_maker
from packit_service.celerizer import celery_app

logger = getLogger("packit_service")

Expand Down Expand Up @@ -656,27 +655,6 @@ def calculate(cls):
known_onboarded_projects
)

if recheck_if_onboarded:
# Run the long running task in Celery.
# The task will collect data about merged PR for
# every given project. If a Packit merged PR is
# found the long running task will save the
# onboarded_downstream flag in the git projects table.
celery_app.send_task(
name="task.check_onboarded_projects",
kwargs={
"projects": [
{
"id": project.id,
"instance_url": project.instance_url,
"namespace": project.namespace,
"repo_name": project.repo_name,
}
for project in recheck_if_onboarded
]
},
)

onboarded = {
project.id: project.project_url
for project in onboarded_projects.union(known_onboarded_projects)
Expand Down
12 changes: 6 additions & 6 deletions packit_service/worker/handlers/usage.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Copyright Contributors to the Packit project.
# SPDX-License-Identifier: MIT

from typing import List, Dict
from typing import Set

from ogr.abstract import PRStatus
from packit_service.config import ServiceConfig
from packit_service.models import GitProjectModel


def check_onboarded_projects(projects: List[Dict]):
def check_onboarded_projects(projects: Set[GitProjectModel]):
"""For every given project check if it has a merged Packit PR.
If yes it is onboarded: save the flag in the git projects table.
"""
for project in projects:
downstream_project_url = f"https://{project['instance_url']}"
downstream_project_url = f"https://{project.instance_url}"
if downstream_project_url != "https://src.fedoraproject.org":
continue

Expand All @@ -24,12 +24,12 @@ def check_onboarded_projects(projects: List[Dict]):
if service.instance_url == downstream_project_url
][0]
ogr_project = pagure_service.get_project(
namespace=project["namespace"],
repo=project["repo_name"],
namespace=project.namespace,
repo=project.repo_name,
)
prs = ogr_project.get_pr_list(status=PRStatus.merged)
prs_from_packit = [pr for pr in prs if pr.author in ("packit", "packit-stg")]

if prs_from_packit:
db_project = GitProjectModel.get_by_id(project["id"])
db_project = GitProjectModel.get_by_id(project.id)
db_project.set_onboarded_downstream(True)
21 changes: 14 additions & 7 deletions packit_service/worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import socket
from os import getenv
from typing import List, Optional, Dict
from typing import List, Optional

from celery import Task
from celery._state import get_current_task
Expand All @@ -22,7 +22,11 @@
DEFAULT_RETRY_BACKOFF,
CELERY_DEFAULT_MAIN_TASK_NAME,
)
from packit_service.models import VMImageBuildTargetModel
from packit_service.models import (
VMImageBuildTargetModel,
GitProjectModel,
SyncReleaseTargetModel,
)
from packit_service.utils import (
load_job_config,
load_package_config,
Expand Down Expand Up @@ -571,8 +575,11 @@ def babysit_pending_vm_image_builds() -> None:
# Usage / statistics tasks


@celery_app.task(
name=TaskName.check_onboarded_projects, queue="long-running", rate_limit="1/h"
)
def run_check_onboarded_projects(projects=List[Dict]) -> None:
check_onboarded_projects(projects)
@celery_app.task
def run_check_onboarded_projects() -> None:
known_onboarded_projects = GitProjectModel.get_known_onboarded_downstream_projects()
downstream_synced_projects = SyncReleaseTargetModel.get_all_downstream_projects()
almost_onboarded_projects = downstream_synced_projects.difference(
known_onboarded_projects
)
check_onboarded_projects(almost_onboarded_projects)

0 comments on commit c1ab816

Please sign in to comment.