Skip to content

Commit

Permalink
WCM-3: use dictionary for webhooks instead of OrderedDict
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinnaj94 committed Oct 1, 2024
1 parent d43dccf commit bff60d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 2 additions & 1 deletion core/src/zeit/cms/checkout/tests/test_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def config(self):
<product_counter>print</product_counter>
</exclude>
</webhook>
<webhook id="publish" url="http://localhost:{port}">
<!-- this webhook will be excluded, see exclude type = testconttype -->
<webhook id="publish" url="http://localhost/two:{port}">
<include>
<product_counter>print</product_counter>
</include>
Expand Down
17 changes: 8 additions & 9 deletions core/src/zeit/cms/checkout/webhook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import collections
import logging

import grokcore.component as grok
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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'))
Expand All @@ -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):
Expand Down

0 comments on commit bff60d7

Please sign in to comment.