Skip to content

Commit

Permalink
frontend: don't show new action task if namespace is deleting itself
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikromen committed Aug 3, 2023
1 parent 0efab6b commit ef18773
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 0 additions & 2 deletions frontend/coprs_frontend/coprs/logic/complex_logic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding: utf-8

import os
import datetime
import time
Expand Down Expand Up @@ -126,7 +125,6 @@ def delete_expired_projects(cls):
print(e)
print("project {} postponed".format(copr.full_name))


@classmethod
def fork_copr(cls, copr, user, dstname, dstgroup=None):
cls.raise_if_cant_fork(user, copr)
Expand Down
24 changes: 21 additions & 3 deletions frontend/coprs_frontend/coprs/views/backend_ns/backend_general.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import flask
from copr_common.enums import StatusEnum
from copr_common.enums import StatusEnum, ActionTypeEnum, ActionObjectTypeEnum
from coprs import db, app
from coprs import models
from coprs.logic import actions_logic
Expand Down Expand Up @@ -287,16 +287,34 @@ def build_task_canceled(task_id):
@backend_ns.route("/pending-actions/")
def pending_actions():
'get the list of actions backand should take care of'
waiting_actions = actions_logic.ActionsLogic.get_waiting()
busy_namespaces = set()
for action in waiting_actions:
if (
action.object_type == ActionObjectTypeEnum.COPR
and action.action_type == ActionTypeEnum("delete")
):
busy_namespaces.add(action.copr.full_name)

data = []
for action in actions_logic.ActionsLogic.get_waiting():
for action in waiting_actions:
if (
action.copr.full_name in busy_namespaces
and action.action_type != ActionTypeEnum("delete")
):
# 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)



@backend_ns.route("/action/<int:action_id>/")
def get_action(action_id):
action = actions_logic.ActionsLogic.get(action_id).one()
Expand Down

0 comments on commit ef18773

Please sign in to comment.