From d965a85aa23bf6a425949c020813607181318ac4 Mon Sep 17 00:00:00 2001 From: Dominik Wombacher Date: Jun 14 2024 14:57:20 +0000 Subject: [PATCH 1/3] fix(runworker): tasks arg at wrong position, name arg missing Name argument moved to right position, otherwise celery fails to start. Name argument introduced to allow spinning up workers with unique names. --- diff --git a/runworker.py b/runworker.py index ffe94c7..577d98d 100755 --- a/runworker.py +++ b/runworker.py @@ -28,7 +28,6 @@ parser.add_argument( default=None, help="Name of the queue to run the worker against.", ) - parser.add_argument( "--tasks", dest="tasks", @@ -42,6 +41,12 @@ parser.add_argument( default=False, help="Reduce the log level.", ) +parser.add_argument( + "--name", + dest="name", + default="worker", + help="Name of the celery worker, has to be unique.", +) args = parser.parse_args() @@ -53,7 +58,7 @@ if args.config: config = os.path.join(here, config) env["PAGURE_CONFIG"] = config -cmd = [sys.executable, "-m", "celery", "-A", "worker", args.tasks] +cmd = [sys.executable, "-m", "celery", "-A", args.tasks, "worker", "-n", args.name] if args.queue: cmd.extend(["-Q", args.queue]) From a594433199e14bc5526731f798542e5517a08f8f Mon Sep 17 00:00:00 2001 From: Dominik Wombacher Date: Jun 14 2024 19:14:59 +0000 Subject: [PATCH 2/3] feat(createdb): Honor env vars, validate parameters. Use values of env vars PAGURE_CONFIG and ALEMBIC_CONFIG if set. Get full path to alembic config and perform check if file exist, similar as for pagure config. --- diff --git a/createdb.py b/createdb.py index 3860b51..974eac7 100644 --- a/createdb.py +++ b/createdb.py @@ -33,17 +33,23 @@ if args.config: if not config.startswith("/"): here = os.path.join(os.path.dirname(os.path.abspath(__file__))) config = os.path.join(here, config) + if not os.path.exists(config): + print("The file `{0}` could not be found".format(config)) + sys.exit(2) os.environ["PAGURE_CONFIG"] = config - if args.alembic_cfg: - if not args.alembic_cfg.endswith("alembic.ini"): + alembic_config = args.alembic_cfg + if not alembic_config.startswith("/"): + here = os.path.join(os.path.dirname(os.path.abspath(__file__))) + alembic_config = os.path.join(here, alembic_config) + if not alembic_config.endswith("alembic.ini"): print("--initial should point to the alembic.ini file to use.") sys.exit(1) - if not os.path.exists(args.alembic_cfg): - print("The file `{0}` could not be found".format(args.alembic_cfg)) + if not os.path.exists(alembic_config): + print("The file `{0}` could not be found".format(alembic_config)) sys.exit(2) - + os.environ["ALEMBIC_CONFIG"] = alembic_config import pagure.config from pagure.lib import model @@ -52,7 +58,7 @@ _config = pagure.config.reload_config() model.create_tables( _config["DB_URL"], - _config.get("PATH_ALEMBIC_INI", args.alembic_cfg), + _config.get("PATH_ALEMBIC_INI", os.environ["ALEMBIC_CONFIG"]), acls=_config.get("ACLS", {}), debug=True, ) From 292365226ab9f24fcfb2ad5d6429767e95bd596e Mon Sep 17 00:00:00 2001 From: Dominik Wombacher Date: Jun 14 2024 23:05:45 +0000 Subject: [PATCH 3/3] tests: Replace usage of pytz with datetime.timezone pytz dropped from some of our indirect dependencies. datetime.timezone ships same functionality since 3.9 out-of-the-box. Fixes ModuleNotFoundError: No module named 'pytz' --- diff --git a/tests/test_pagure_flask_api_user.py b/tests/test_pagure_flask_api_user.py index ea611c7..97e3aed 100644 --- a/tests/test_pagure_flask_api_user.py +++ b/tests/test_pagure_flask_api_user.py @@ -12,7 +12,6 @@ from __future__ import unicode_literals, absolute_import import datetime import os -import pytz import shutil import sys import unittest @@ -30,6 +29,8 @@ import pagure.lib.model as model import pagure.lib.query import tests +import zoneinfo + class PagureFlaskApiUSertests(tests.Modeltests): """Tests for the flask API of pagure for issue""" @@ -550,8 +551,12 @@ class PagureFlaskApiUSertests(tests.Modeltests): utcts = str( int( ( - datetime.datetime(year, 2, 15, 12, 0, tzinfo=pytz.UTC) - - datetime.datetime(1970, 1, 1, tzinfo=pytz.UTC) + datetime.datetime( + year, 2, 15, 12, 0, tzinfo=datetime.timezone.utc + ) + - datetime.datetime( + 1970, 1, 1, tzinfo=datetime.timezone.utc + ) ).total_seconds() ) ) @@ -566,10 +571,13 @@ class PagureFlaskApiUSertests(tests.Modeltests): 14, 17, 0, - tzinfo=pytz.timezone("America/New_York"), + tzinfo=zoneinfo.ZoneInfo("America/New_York"), ) - datetime.datetime( - 1970, 1, 1, tzinfo=pytz.timezone("America/New_York") + 1970, + 1, + 1, + tzinfo=zoneinfo.ZoneInfo("America/New_York"), ) ).total_seconds() ) @@ -667,8 +675,12 @@ class PagureFlaskApiUSertests(tests.Modeltests): utcts = str( int( ( - datetime.datetime(year, 2, 15, 12, 0, tzinfo=pytz.UTC) - - datetime.datetime(1970, 1, 1, tzinfo=pytz.UTC) + datetime.datetime( + year, 2, 15, 12, 0, tzinfo=datetime.timezone.utc + ) + - datetime.datetime( + 1970, 1, 1, tzinfo=datetime.timezone.utc + ) ).total_seconds() ) ) @@ -678,10 +690,15 @@ class PagureFlaskApiUSertests(tests.Modeltests): int( ( datetime.datetime( - year, 2, 16, 8, 0, tzinfo=pytz.timezone("Asia/Dubai") + year, + 2, + 16, + 8, + 0, + tzinfo=zoneinfo.ZoneInfo("Asia/Dubai"), ) - datetime.datetime( - 1970, 1, 1, tzinfo=pytz.timezone("Asia/Dubai") + 1970, 1, 1, tzinfo=zoneinfo.ZoneInfo("Asia/Dubai") ) ).total_seconds() )