From 20ad254db7c6824144f90da9935f4721ca4ac9fc Mon Sep 17 00:00:00 2001 From: Jiri Kyjovsky Date: Mon, 10 Jul 2023 13:22:43 +0200 Subject: [PATCH] frontend: don't show new action task if namespace is deleting itself wait for the end of the deletion of project to avoid race condition when other action like fork or create is called immidiatelly after delete --- frontend/coprs_frontend/coprs/models.py | 1 + .../coprs/views/backend_ns/backend_general.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/frontend/coprs_frontend/coprs/models.py b/frontend/coprs_frontend/coprs/models.py index 2502783ae..62f994b3d 100644 --- a/frontend/coprs_frontend/coprs/models.py +++ b/frontend/coprs_frontend/coprs/models.py @@ -2129,6 +2129,7 @@ class Action(db.Model, helpers.Serializer): # see ActionTypeEnum action_type = db.Column(db.Integer, nullable=False) # copr, ...; downcase name of class of modified object + # TODO: replace this in the future with something better object_type = db.Column(db.String(20)) # id of the modified object object_id = db.Column(db.Integer) diff --git a/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py b/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py index 59a11c877..fef12fc39 100755 --- a/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py +++ b/frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py @@ -1,5 +1,5 @@ import flask -from copr_common.enums import StatusEnum +from copr_common.enums import StatusEnum, ActionTypeEnum from coprs import db, app from coprs import models from coprs.logic import actions_logic @@ -287,14 +287,28 @@ def build_task_canceled(task_id): @backend_ns.route("/pending-actions/") def pending_actions(): 'get the list of actions backand should take care of' + busy_namespaces = set() data = [] + # waiting repos are ordered for action in actions_logic.ActionsLogic.get_waiting(): + if ( + action.object_type == "copr" + and action.action_type == ActionTypeEnum("delete") + ): + busy_namespaces.add(action.copr.full_name) + elif action.copr.full_name in busy_namespaces: + # e.g. copr delete _ && copr fork _; will cause race condition + # so don't process new action with the same namespace until delete + # action is processed + # https://github.com/fedora-copr/copr/issues/2698 + continue + data.append({ 'id': action.id, 'priority': action.priority or action.default_priority, }) - return flask.json.dumps(data) + return flask.json.dumps(data) @backend_ns.route("/action//")