diff --git a/alembic/versions/7f31a9fad89f_expand_enum_for_lock_types.py b/alembic/versions/7f31a9fad89f_expand_enum_for_lock_types.py new file mode 100644 index 0000000..8af08e0 --- /dev/null +++ b/alembic/versions/7f31a9fad89f_expand_enum_for_lock_types.py @@ -0,0 +1,38 @@ +"""expand enum for lock types + +Revision ID: 7f31a9fad89f +Revises: 369deb8c8b63 +Create Date: 2018-04-16 15:01:00.280469 + +""" + +# revision identifiers, used by Alembic. +revision = '7f31a9fad89f' +down_revision = '369deb8c8b63' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + """ + Add new lock types to the lock_type_enum enum. + + With this there are three enums: + - WORKER, used to lock action on the main git repo (sources) + - WORKER_TICKET, used to lock actions on the ticket git repo + - WORKER_REQUEST, used to lock actions on the request git repo + """ + + # Let's start with commit to close the current transaction + # cf https://bitbucket.org/zzzeek/alembic/issue/123 + op.execute('COMMIT') + op.execute( + "ALTER TYPE lock_type_enum ADD VALUE 'WORKER_TICKET';") + op.execute( + "ALTER TYPE lock_type_enum ADD VALUE 'WORKER_REQUEST';") + + +def downgrade(): + """Raise an exception explaining that this migration cannot be reversed.""" + raise NotImplemented('This migration cannot be reversed.') diff --git a/pagure/lib/model.py b/pagure/lib/model.py index b9c1e35..8da2fc8 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -921,7 +921,7 @@ class ProjectLock(BASE): primary_key=True) lock_type = sa.Column( sa.Enum( - 'WORKER', + 'WORKER', 'WORKER_TICKET', 'WORKER_REQUEST', name='lock_type_enum', ), nullable=False, diff --git a/pagure/lib/tasks.py b/pagure/lib/tasks.py index 5d1579d..3e2d6fc 100644 --- a/pagure/lib/tasks.py +++ b/pagure/lib/tasks.py @@ -386,7 +386,13 @@ def update_git(self, session, name, namespace, user, session, namespace=namespace, name=name, user=user, case=pagure_config.get('CASE_SENSITIVE', False)) - with project.lock('WORKER'): + project_lock = 'WORKER' + if ticketuid is not None: + project_lock = 'WORKER_TICKET' + elif requestuid is not None: + project_lock = 'WORKER_REQUEST' + + with project.lock(project_lock): if ticketuid is not None: obj = pagure.lib.get_issue_by_uid(session, ticketuid) folder = pagure_config['TICKETS_FOLDER'] @@ -414,7 +420,7 @@ def clean_git(self, session, name, namespace, user, ticketuid): session, namespace=namespace, name=name, user=user, case=pagure_config.get('CASE_SENSITIVE', False)) - with project.lock('WORKER'): + with project.lock('WORKER_TICKET'): obj = pagure.lib.get_issue_by_uid(session, ticketuid) folder = pagure_config['TICKETS_FOLDER']