Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temp workaround for celery/kombu#1804 issue #652

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions osism/tasks/ansible.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# SPDX-License-Identifier: Apache-2.0

import functools
from threading import RLock

from celery import Celery
import kombu.utils

from osism import settings
from osism.tasks import Config, run_ansible_in_environment

# https://github.com/celery/kombu/issues/1804
if not getattr(kombu.utils.cached_property, "lock", None):
setattr(
kombu.utils.cached_property,
"lock",
functools.cached_property(lambda _: RLock()),
)
# Must call __set_name__ here since this cached property is not defined in the context of a class
# Refer to https://docs.python.org/3/reference/datamodel.html#object.__set_name__
kombu.utils.cached_property.lock.__set_name__(kombu.utils.cached_property, "lock")

app = Celery("ansible")
app.config_from_object(Config)

Expand Down
15 changes: 15 additions & 0 deletions osism/tasks/openstack.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
# SPDX-License-Identifier: Apache-2.0

import functools
import copy
import ipaddress
from threading import RLock

from celery import Celery
from celery.signals import worker_process_init
import jinja2
import keystoneauth1
import kombu.utils
import openstack
from pottery import Redlock
from redis import Redis

from osism import settings
from osism.tasks import Config, conductor, netbox
from osism import utils

# https://github.com/celery/kombu/issues/1804
if not getattr(kombu.utils.cached_property, "lock", None):
setattr(
kombu.utils.cached_property,
"lock",
functools.cached_property(lambda _: RLock()),
)
# Must call __set_name__ here since this cached property is not defined in the context of a class
# Refer to https://docs.python.org/3/reference/datamodel.html#object.__set_name__
kombu.utils.cached_property.lock.__set_name__(kombu.utils.cached_property, "lock")

app = Celery("openstack")
app.config_from_object(Config)

Expand Down
16 changes: 16 additions & 0 deletions osism/tasks/reconciler.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
# SPDX-License-Identifier: Apache-2.0

import functools
import io
import subprocess
from threading import RLock

from celery import Celery
from celery.signals import worker_process_init
import kombu.utils
from pottery import Redlock
from redis import Redis

from osism import settings
from osism.tasks import Config


# https://github.com/celery/kombu/issues/1804
if not getattr(kombu.utils.cached_property, "lock", None):
setattr(
kombu.utils.cached_property,
"lock",
functools.cached_property(lambda _: RLock()),
)
# Must call __set_name__ here since this cached property is not defined in the context of a class
# Refer to https://docs.python.org/3/reference/datamodel.html#object.__set_name__
kombu.utils.cached_property.lock.__set_name__(kombu.utils.cached_property, "lock")

app = Celery("reconciler")
app.config_from_object(Config)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Add workaround for https://github.com/celery/kombu/issues/1804 to solve the
`after fork raised exception: AttributeError("'cached_property' object has no attribute 'lock'")`
issue for services already using Python 3.12.