Skip to content

Commit 14fca52

Browse files
authored
Jlc/tenant async settings fix (#260)
* Revert "fix: remove unused line in signals (#247)" This reverts commit d97d3ec. * feat: support task protocol v2 Change inspired in nelc/eox-nelp@64a07d5 https://docs.celeryq.dev/en/latest/internals/protocol.html#changes-from-version-1 * feat: fix tests
1 parent 3aca561 commit 14fca52

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

eox_tenant/signals.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ def tenant_context_addition(sender, body, headers, *args, **kwargs): # pylint:
232232

233233
get_host_func = AsyncTaskHandler().get_host_from_task(sender)
234234
headers['eox_tenant_sender'] = get_host_func(body)
235+
body[1]['eox_tenant_sender'] = get_host_func(body) # body = (args, kwargs, Mapping embed)
235236

236237

237238
def start_async_lms_tenant(sender, *args, **kwargs): # pylint: disable=unused-argument
@@ -262,6 +263,7 @@ def _start_async_tenant(sender, config_key):
262263
context = sender.request
263264
headers = context.get('headers') or {}
264265
http_host = headers.get('eox_tenant_sender')
266+
http_host = context.get('kwargs', {}).pop('eox_tenant_sender', http_host)
265267

266268
if not http_host: # Reset settings in case of no tenant.
267269
LOG.warning("Could not find the host information for eox_tenant.signals. ")

eox_tenant/test/test_signals.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ class CeleryReceiverCLISyncTests(TestCase):
300300

301301
def setUp(self):
302302
""" setup """
303-
self.body = {
304-
'kwargs': {},
305-
}
303+
args = []
304+
kwargs = {} # This is the default value for kwargs
305+
self.body = (args, kwargs)
306306
for number in range(3):
307307
Site.objects.create(
308308
domain=f"tenant{number}.com",
@@ -354,9 +354,10 @@ def test_sync_process_with_tenant(self):
354354
When the task is called from a sync proccess it is used the value of the 'host' key in the request dict.
355355
"""
356356
headers = {}
357-
body = {
358-
'kwargs': {},
359-
}
357+
args = []
358+
kwargs = {}
359+
body = (args, kwargs)
360+
360361
with self.settings(EDNX_TENANT_DOMAIN="some.tenant.com"):
361362
tenant_context_addition("some.task", headers=headers, body=body)
362363

0 commit comments

Comments
 (0)