From bff60d73be82b9f4a858cff9cc3b56be13078c49 Mon Sep 17 00:00:00 2001 From: Jannis Jahr Date: Tue, 1 Oct 2024 11:20:35 +0200 Subject: [PATCH] WCM-3: use dictionary for webhooks instead of OrderedDict --- .../src/zeit/cms/checkout/tests/test_webhook.py | 3 ++- core/src/zeit/cms/checkout/webhook.py | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/zeit/cms/checkout/tests/test_webhook.py b/core/src/zeit/cms/checkout/tests/test_webhook.py index ff7a99b6d4..86d7eaeeac 100644 --- a/core/src/zeit/cms/checkout/tests/test_webhook.py +++ b/core/src/zeit/cms/checkout/tests/test_webhook.py @@ -159,7 +159,8 @@ def config(self): print - + + print diff --git a/core/src/zeit/cms/checkout/webhook.py b/core/src/zeit/cms/checkout/webhook.py index 4b27bf2e3e..57e99b9cf4 100644 --- a/core/src/zeit/cms/checkout/webhook.py +++ b/core/src/zeit/cms/checkout/webhook.py @@ -1,4 +1,3 @@ -import collections import logging import grokcore.component as grok @@ -23,12 +22,12 @@ def create_webhook_jobs(id, context, **kwargs): if not hooks: log.warning('No %s webhooks found for %s', id, context.uniqueId) return - for index, hook in enumerate(hooks): + for url in hooks: log.info( f'After{id.capitalize()}: Creating async webhook jobs with' - f' index {index} for {context.uniqueId}', + f' url {url} for {context.uniqueId}', ) - notify_webhook.apply_async((context.uniqueId, id, index), **kwargs) + notify_webhook.apply_async((context.uniqueId, id, url), **kwargs) @grok.subscribe(zeit.cms.interfaces.ICMSContent, zeit.cms.checkout.interfaces.IAfterCheckinEvent) @@ -57,7 +56,7 @@ def notify_after_add(event): @zeit.cms.celery.task(bind=True, queue='webhook') -def notify_webhook(self, uniqueId, id, index=0): +def notify_webhook(self, uniqueId, id, url): content = zeit.cms.interfaces.ICMSContent(uniqueId, None) if content is None: log.warning('Could not resolve %s, ignoring.', uniqueId) @@ -67,7 +66,7 @@ def notify_webhook(self, uniqueId, id, index=0): log.warning('Hook configuration for %s has vanished, ignoring.', id) return try: - hooks[index](content) + hooks[url](content) except TechnicalError as e: raise self.retry(countdown=e.countdown) # Don't even think about trying to write to DAV cache, to avoid conflicts. @@ -158,7 +157,7 @@ class HookSource(zeit.cms.content.sources.SimpleXMLSource): @CONFIG_CACHE.cache_on_arguments() def _values(self): - result = collections.OrderedDict() + result = {} tree = self._get_tree() for node in tree.iterchildren('webhook'): hook = Hook(node.get('id'), node.get('url')) @@ -167,8 +166,8 @@ def _values(self): for exclude in node.xpath('exclude/*'): hook.add_exclude(exclude.tag, exclude.text) if not result.get(hook.id): - result[hook.id] = [] - result[hook.id].append(hook) + result[hook.id] = {} + result[hook.id][hook.url] = hook return result def getValues(self):