From e4aa31a7e37afd9bc0d63b0ca9e1c779efd2bdfe Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 26 Jan 2022 15:30:01 +0100 Subject: [PATCH] TT#121955 repoapi: don't use send_task directly Change-Id: Iffcd0c084281158106d8c582930331f841af9757 --- repoapi/celery.py | 9 ++++++++- repoapi/tasks.py | 6 ++---- repoapi/test/test_jbi_info.py | 8 +++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/repoapi/celery.py b/repoapi/celery.py index 404f0ba..3723354 100644 --- a/repoapi/celery.py +++ b/repoapi/celery.py @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2020 The Sipwise Team - http://sipwise.com +# Copyright (C) 2016-2022 The Sipwise Team - http://sipwise.com # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -92,3 +92,10 @@ def receiver_setup_logging(loglevel, logfile, format, colorize, **kwargs): @app.task() def jbi_parse_hotfix(jbi_id, path): app.send_task("hotfix.tasks.hotfix_released", args=[jbi_id, path]) + + +@app.task() +def process_result(jbi_id, path_envVars): + app.send_task( + "release_changed.tasks.process_result", args=[jbi_id, path_envVars] + ) diff --git a/repoapi/tasks.py b/repoapi/tasks.py index 03d1221..b0109eb 100644 --- a/repoapi/tasks.py +++ b/repoapi/tasks.py @@ -19,8 +19,8 @@ import structlog from celery import shared_task from django.apps import apps -from .celery import app from .celery import jbi_parse_hotfix +from .celery import process_result from .conf import settings from .utils import is_download_artifacts from .utils import jenkins_get_artifact @@ -77,9 +77,7 @@ def get_jbi_files(jbi_id, jobname, buildnumber): else: log.debug("skip artifacts download") if jobname in settings.RELEASE_CHANGED_JOBS: - app.send_task( - "release_changed.tasks.process_result", args=[jbi_id, path_envVars] - ) + process_result.delay(jbi_id, path_envVars) @shared_task(ignore_result=True) diff --git a/repoapi/test/test_jbi_info.py b/repoapi/test/test_jbi_info.py index be4f9be..2ec0f69 100644 --- a/repoapi/test/test_jbi_info.py +++ b/repoapi/test/test_jbi_info.py @@ -140,8 +140,8 @@ class TestJBICelery(BaseTest): class TestJBIReleaseChangedCelery(BaseTest): @patch("builtins.open", mock_open(read_data=artifacts_json)) @patch("repoapi.utils.dlfile") - @patch("repoapi.tasks.app") - def test_jbi_release_changed(self, app, dlfile): + @patch("repoapi.tasks.process_result") + def test_jbi_release_changed(self, process_result, dlfile): param = { "projectname": "check-ngcp-release-changes", "jobname": "check-ngcp-release-changes", @@ -157,6 +157,4 @@ class TestJBIReleaseChangedCelery(BaseTest): ) path = base_path.joinpath("envVars.json") dlfile.assert_any_call(url, path) - app.send_task.assert_called_once_with( - "release_changed.tasks.process_result", args=[jbi.id, path] - ) + process_result.delay.assert_called_once_with(jbi.id, path)