##// END OF EJS Templates
webhook: execute via celery for async.
marcink -
r2410:af8ad232 default
parent child Browse files
Show More
@@ -34,7 +34,7 b' import rhodecode'
34 from rhodecode import events
34 from rhodecode import events
35 from rhodecode.translation import _
35 from rhodecode.translation import _
36 from rhodecode.integrations.types.base import IntegrationTypeBase
36 from rhodecode.integrations.types.base import IntegrationTypeBase
37 from rhodecode.lib.celerylib import async_task, RequestContextTask
37 from rhodecode.lib.celerylib import run_task, async_task, RequestContextTask
38
38
39 log = logging.getLogger(__name__)
39 log = logging.getLogger(__name__)
40
40
@@ -313,11 +313,47 b' class WebhookIntegrationType(Integration'
313 url_calls = handler(event, data)
313 url_calls = handler(event, data)
314 log.debug('webhook: calling following urls: %s',
314 log.debug('webhook: calling following urls: %s',
315 [x[0] for x in url_calls])
315 [x[0] for x in url_calls])
316 post_to_webhook(url_calls, self.settings)
316
317 run_task(post_to_webhook, url_calls, self.settings)
317
318
318
319
319 @async_task(ignore_result=True, base=RequestContextTask)
320 @async_task(ignore_result=True, base=RequestContextTask)
320 def post_to_webhook(url_calls, settings):
321 def post_to_webhook(url_calls, settings):
322 """
323 Example data::
324
325 {'actor': {'user_id': 2, 'username': u'admin'},
326 'actor_ip': u'192.168.157.1',
327 'name': 'repo-push',
328 'push': {'branches': [{'name': u'default',
329 'url': 'http://rc.local:8080/hg-repo/changelog?branch=default'}],
330 'commits': [{'author': u'Marcin Kuzminski <marcin@rhodecode.com>',
331 'branch': u'default',
332 'date': datetime.datetime(2017, 11, 30, 12, 59, 48),
333 'issues': [],
334 'mentions': [],
335 'message': u'commit Thu 30 Nov 2017 13:59:48 CET',
336 'message_html': u'commit Thu 30 Nov 2017 13:59:48 CET',
337 'message_html_title': u'commit Thu 30 Nov 2017 13:59:48 CET',
338 'parents': [{'raw_id': '431b772a5353dad9974b810dd3707d79e3a7f6e0'}],
339 'permalink_url': u'http://rc.local:8080/_7/changeset/a815cc738b9651eb5ffbcfb1ce6ccd7c701a5ddf',
340 'raw_id': 'a815cc738b9651eb5ffbcfb1ce6ccd7c701a5ddf',
341 'refs': {'bookmarks': [], 'branches': [u'default'], 'tags': [u'tip']},
342 'reviewers': [],
343 'revision': 9L,
344 'short_id': 'a815cc738b96',
345 'url': u'http://rc.local:8080/hg-repo/changeset/a815cc738b9651eb5ffbcfb1ce6ccd7c701a5ddf'}],
346 'issues': {}},
347 'repo': {'extra_fields': '',
348 'permalink_url': u'http://rc.local:8080/_7',
349 'repo_id': 7,
350 'repo_name': u'hg-repo',
351 'repo_type': u'hg',
352 'url': u'http://rc.local:8080/hg-repo'},
353 'server_url': u'http://rc.local:8080',
354 'utc_timestamp': datetime.datetime(2017, 11, 30, 13, 0, 1, 569276)
355
356 """
321 max_retries = 3
357 max_retries = 3
322 retries = Retry(
358 retries = Retry(
323 total=max_retries,
359 total=max_retries,
@@ -342,6 +378,7 b' def post_to_webhook(url_calls, settings)'
342
378
343 log.debug('calling Webhook with method: %s, and auth:%s',
379 log.debug('calling Webhook with method: %s, and auth:%s',
344 call_method, auth)
380 call_method, auth)
381
345 resp = call_method(url, json={
382 resp = call_method(url, json={
346 'token': token,
383 'token': token,
347 'event': data
384 'event': data
General Comments 0
You need to be logged in to leave comments. Login now