summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Rominger <arominge@redhat.com>2025-01-15 20:06:59 +0100
committerGitHub <noreply@github.com>2025-01-15 20:06:59 +0100
commitf57a9863d686505aa68b857c537d77e1b7cf538b (patch)
treec077d97228107a15d831a0762787621685cd18be
parentBump awx collection ansible required version (diff)
downloadawx-f57a9863d686505aa68b857c537d77e1b7cf538b.tar.xz
awx-f57a9863d686505aa68b857c537d77e1b7cf538b.zip
Use advisory_lock from DAB (#15676)
* Use advisory_lock from DAB * Remove the django-pglocks dep * Re-run updater script * Move the import in new location
-rw-r--r--awx/main/analytics/core.py4
-rw-r--r--awx/main/management/commands/deprovision_instance.py3
-rw-r--r--awx/main/management/commands/inventory_import.py4
-rw-r--r--awx/main/management/commands/register_queue.py3
-rw-r--r--awx/main/management/commands/unregister_queue.py3
-rw-r--r--awx/main/managers.py4
-rw-r--r--awx/main/models/credential.py4
-rw-r--r--awx/main/scheduler/task_manager.py4
-rw-r--r--awx/main/tasks/host_metrics.py2
-rw-r--r--awx/main/tasks/receptor.py4
-rw-r--r--awx/main/tasks/system.py2
-rw-r--r--awx/main/utils/pglock.py29
-rw-r--r--licenses/django-pglocks.txt3
-rw-r--r--requirements/requirements.in1
-rw-r--r--requirements/requirements.txt3
15 files changed, 26 insertions, 47 deletions
diff --git a/awx/main/analytics/core.py b/awx/main/analytics/core.py
index 1195b262ba..9efe27337c 100644
--- a/awx/main/analytics/core.py
+++ b/awx/main/analytics/core.py
@@ -16,10 +16,12 @@ from rest_framework.exceptions import PermissionDenied
import requests
from awx.conf.license import get_license
+
+from ansible_base.lib.utils.db import advisory_lock
+
from awx.main.models import Job
from awx.main.access import access_registry
from awx.main.utils import get_awx_http_client_headers, set_environ, datetime_hook
-from awx.main.utils.pglock import advisory_lock
__all__ = ['register', 'gather', 'ship']
diff --git a/awx/main/management/commands/deprovision_instance.py b/awx/main/management/commands/deprovision_instance.py
index 470694d363..ff906e2030 100644
--- a/awx/main/management/commands/deprovision_instance.py
+++ b/awx/main/management/commands/deprovision_instance.py
@@ -4,8 +4,9 @@
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
+from ansible_base.lib.utils.db import advisory_lock
+
from awx.main.models import Instance
-from awx.main.utils.pglock import advisory_lock
class Command(BaseCommand):
diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py
index 582af9d03b..29ab6ba627 100644
--- a/awx/main/management/commands/inventory_import.py
+++ b/awx/main/management/commands/inventory_import.py
@@ -21,6 +21,9 @@ from django.utils.encoding import smart_str
# DRF error class to distinguish license exceptions
from rest_framework.exceptions import PermissionDenied
+# django-ansible-base
+from ansible_base.lib.utils.db import advisory_lock
+
# AWX inventory imports
from awx.main.models.inventory import Inventory, InventorySource, InventoryUpdate, Host
from awx.main.utils.mem_inventory import MemInventory, dict_to_mem_data
@@ -32,7 +35,6 @@ from awx.main.utils import ignore_inventory_computed_fields, get_licenser
from awx.main.utils.execution_environments import get_default_execution_environment
from awx.main.signals import disable_activity_stream
from awx.main.constants import STANDARD_INVENTORY_UPDATE_ENV
-from awx.main.utils.pglock import advisory_lock
logger = logging.getLogger('awx.main.commands.inventory_import')
diff --git a/awx/main/management/commands/register_queue.py b/awx/main/management/commands/register_queue.py
index 36b7d17b1b..9b8af6e031 100644
--- a/awx/main/management/commands/register_queue.py
+++ b/awx/main/management/commands/register_queue.py
@@ -2,7 +2,8 @@
# All Rights Reserved.
import sys
-from awx.main.utils.pglock import advisory_lock
+from ansible_base.lib.utils.db import advisory_lock
+
from awx.main.models import Instance, InstanceGroup
from django.core.management.base import BaseCommand, CommandError
diff --git a/awx/main/management/commands/unregister_queue.py b/awx/main/management/commands/unregister_queue.py
index 729c309788..f26f877d3f 100644
--- a/awx/main/management/commands/unregister_queue.py
+++ b/awx/main/management/commands/unregister_queue.py
@@ -2,7 +2,8 @@
# All Rights Reserved.
import sys
-from awx.main.utils.pglock import advisory_lock
+from ansible_base.lib.utils.db import advisory_lock
+
from awx.main.models import InstanceGroup
from django.db import transaction
diff --git a/awx/main/managers.py b/awx/main/managers.py
index c501d7b0d3..c754af3b38 100644
--- a/awx/main/managers.py
+++ b/awx/main/managers.py
@@ -6,8 +6,10 @@ import uuid
from django.db import models
from django.conf import settings
from django.db.models.functions import Lower
+
+from ansible_base.lib.utils.db import advisory_lock
+
from awx.main.utils.filters import SmartFilter
-from awx.main.utils.pglock import advisory_lock
from awx.main.constants import RECEPTOR_PENDING
___all__ = ['HostManager', 'InstanceManager', 'DeferJobCreatedManager', 'UUID_DEFAULT']
diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py
index 1cdf11d135..09cc4bde7c 100644
--- a/awx/main/models/credential.py
+++ b/awx/main/models/credential.py
@@ -23,9 +23,11 @@ from django.contrib.auth.models import User
# DRF
-from awx.main.utils.pglock import advisory_lock
from rest_framework.serializers import ValidationError as DRFValidationError
+# django-ansible-base
+from ansible_base.lib.utils.db import advisory_lock
+
# AWX
from awx.api.versioning import reverse
from awx.main.fields import (
diff --git a/awx/main/scheduler/task_manager.py b/awx/main/scheduler/task_manager.py
index 9ded09dd78..835e99d4b0 100644
--- a/awx/main/scheduler/task_manager.py
+++ b/awx/main/scheduler/task_manager.py
@@ -19,6 +19,9 @@ from django.contrib.contenttypes.models import ContentType
from ansible_base.lib.utils.models import get_type_for_model
+# django-ansible-base
+from ansible_base.lib.utils.db import advisory_lock
+
# AWX
from awx.main.dispatch.reaper import reap_job
from awx.main.models import (
@@ -34,7 +37,6 @@ from awx.main.models import (
WorkflowJobTemplate,
)
from awx.main.scheduler.dag_workflow import WorkflowDAG
-from awx.main.utils.pglock import advisory_lock
from awx.main.utils import (
ScheduleTaskManager,
ScheduleWorkflowManager,
diff --git a/awx/main/tasks/host_metrics.py b/awx/main/tasks/host_metrics.py
index 9e163cfa73..999f4b63f1 100644
--- a/awx/main/tasks/host_metrics.py
+++ b/awx/main/tasks/host_metrics.py
@@ -11,7 +11,7 @@ from awx.main.dispatch.publish import task
from awx.main.models.inventory import HostMetric, HostMetricSummaryMonthly
from awx.main.tasks.helpers import is_run_threshold_reached
from awx.conf.license import get_license
-from awx.main.utils.pglock import advisory_lock
+from ansible_base.lib.utils.db import advisory_lock
logger = logging.getLogger('awx.main.tasks.host_metrics')
diff --git a/awx/main/tasks/receptor.py b/awx/main/tasks/receptor.py
index 58c2e895cc..2fbf6791ed 100644
--- a/awx/main/tasks/receptor.py
+++ b/awx/main/tasks/receptor.py
@@ -17,6 +17,9 @@ from django.db import connections
# Runner
import ansible_runner
+# django-ansible-base
+from ansible_base.lib.utils.db import advisory_lock
+
# AWX
from awx.main.utils.execution_environments import get_default_pod_spec
from awx.main.exceptions import ReceptorNodeNotFound
@@ -30,7 +33,6 @@ from awx.main.tasks.signals import signal_state, signal_callback, SignalExit
from awx.main.models import Instance, InstanceLink, UnifiedJob, ReceptorAddress
from awx.main.dispatch import get_task_queuename
from awx.main.dispatch.publish import task
-from awx.main.utils.pglock import advisory_lock
# Receptorctl
from receptorctl.socket_interface import ReceptorControl
diff --git a/awx/main/tasks/system.py b/awx/main/tasks/system.py
index e0bb0dfc9f..6d161d2ef8 100644
--- a/awx/main/tasks/system.py
+++ b/awx/main/tasks/system.py
@@ -38,6 +38,7 @@ from dateutil.parser import parse as parse_date
# django-ansible-base
from ansible_base.resource_registry.tasks.sync import SyncExecutor
+from ansible_base.lib.utils.db import advisory_lock
# AWX
from awx import __version__ as awx_application_version
@@ -60,7 +61,6 @@ from awx.main.dispatch import get_task_queuename, reaper
from awx.main.utils.common import ignore_inventory_computed_fields, ignore_inventory_group_removal
from awx.main.utils.reload import stop_local_services
-from awx.main.utils.pglock import advisory_lock
from awx.main.tasks.helpers import is_run_threshold_reached
from awx.main.tasks.receptor import get_receptor_ctl, worker_info, worker_cleanup, administrative_workunit_reaper, write_receptor_config
from awx.main.consumers import emit_channel_notification
diff --git a/awx/main/utils/pglock.py b/awx/main/utils/pglock.py
deleted file mode 100644
index d599d284b3..0000000000
--- a/awx/main/utils/pglock.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright (c) 2017 Ansible by Red Hat
-# All Rights Reserved.
-
-from contextlib import contextmanager
-
-from django_pglocks import advisory_lock as django_pglocks_advisory_lock
-from django.db import connection
-
-
-@contextmanager
-def advisory_lock(*args, lock_session_timeout_milliseconds=0, **kwargs):
- if connection.vendor == 'postgresql':
- cur = None
- idle_in_transaction_session_timeout = None
- idle_session_timeout = None
- if lock_session_timeout_milliseconds > 0:
- with connection.cursor() as cur:
- idle_in_transaction_session_timeout = cur.execute('SHOW idle_in_transaction_session_timeout').fetchone()[0]
- idle_session_timeout = cur.execute('SHOW idle_session_timeout').fetchone()[0]
- cur.execute(f"SET idle_in_transaction_session_timeout = '{lock_session_timeout_milliseconds}'")
- cur.execute(f"SET idle_session_timeout = '{lock_session_timeout_milliseconds}'")
- with django_pglocks_advisory_lock(*args, **kwargs) as internal_lock:
- yield internal_lock
- if lock_session_timeout_milliseconds > 0:
- with connection.cursor() as cur:
- cur.execute(f"SET idle_in_transaction_session_timeout = '{idle_in_transaction_session_timeout}'")
- cur.execute(f"SET idle_session_timeout = '{idle_session_timeout}'")
- else:
- yield True
diff --git a/licenses/django-pglocks.txt b/licenses/django-pglocks.txt
deleted file mode 100644
index 3b74730882..0000000000
--- a/licenses/django-pglocks.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-Copyright (c) 2013 Christophe Pettus
-
-Licensed under the MIT License.
diff --git a/requirements/requirements.in b/requirements/requirements.in
index 5ef696c18b..181bce1529 100644
--- a/requirements/requirements.in
+++ b/requirements/requirements.in
@@ -19,7 +19,6 @@ django-extensions
django-guid
django-oauth-toolkit<2.0.0 # Version 2.0.0 has breaking changes that will need to be worked out before upgrading
django-polymorphic
-django-pglocks
django-solo
django-split-settings
djangorestframework>=3.15.0
diff --git a/requirements/requirements.txt b/requirements/requirements.txt
index 815ec41cec..e88a669ca4 100644
--- a/requirements/requirements.txt
+++ b/requirements/requirements.txt
@@ -147,8 +147,6 @@ django-guid==3.5.0
# via -r /awx_devel/requirements/requirements.in
django-oauth-toolkit==1.7.1
# via -r /awx_devel/requirements/requirements.in
-django-pglocks==1.0.4
- # via -r /awx_devel/requirements/requirements.in
django-polymorphic==3.1.0
# via -r /awx_devel/requirements/requirements.in
django-solo==2.4.0
@@ -456,7 +454,6 @@ setuptools-scm[toml]==8.1.0
six==1.17.0
# via
# azure-core
- # django-pglocks
# kubernetes
# msrestazure
# openshift