Skip to content

Commit

Permalink
Temp workaround for celery/kombu#1804 issue (#652)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt authored Oct 29, 2023
1 parent e2e882e commit f77a2be
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
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.

0 comments on commit f77a2be

Please sign in to comment.