def call_webhook(event, webhook, payload):
    """Build request from event,webhook,payoad and parse response."""
    started_at = time()

    request = _build_request_for_calling_webhook(event, webhook, payload)

    logger.info('REQUEST %(uuid)s %(method)s %(url)s %(payload)s' % dict(
        uuid=str(event['uuid']),
        url=request['url'],
        method=request['method'],
        payload=payload,
    ))

    try:
        content = dispatch_webhook_request(**request)

        logger.debug('RESPONSE %(uuid)s %(method)s %(url)s %(data)s' % dict(
            uuid=str(event['uuid']),
            url=request['url'],
            method=request['method'],
            data=content,
        ))

        data = dict(
            parent=str(event['uuid']),
            content=content,
            started_at=started_at,
            ended_at=time()
        )
    except (FailureWebhookError, ConnectionError) as exception:
        if sentry.client:
            http_context = raven_context(**request)
            sentry.captureException(data={'request': http_context})

        logger.error('RESPONSE %(uuid)s %(method)s %(url)s %(error)s' % dict(
            uuid=str(event['uuid']),
            method=request['method'],
            url=request['url'],
            error=exception.message,))

        data = dict(
            parent=str(event['uuid']),
            error=exception.message,
            started_at=started_at,
            ended_at=time(),
        )

    webhook_ran.send(None, data=data)

    return data
def call_webhook ( event , webhook , payload ) : started_at = time ( ) request = _build_request_for_calling_webhook ( event , webhook , payload ) logger . info ( 'REQUEST %(uuid)s %(method)s %(url)s %(payload)s' % dict ( uuid = str ( event [ 'uuid' ] ) , url = request [ 'url' ] , method = request [ 'method' ] , payload = payload , ) ) try : content = dispatch_webhook_request ( ** request ) logger . debug ( 'RESPONSE %(uuid)s %(method)s %(url)s %(data)s' % dict ( uuid = str ( event [ 'uuid' ] ) , url = request [ 'url' ] , method = request [ 'method' ] , data = content , ) ) data = dict ( parent = str ( event [ 'uuid' ] ) , content = content , started_at = started_at , ended_at = time ( ) ) except ( FailureWebhookError , ConnectionError ) as exception : if sentry . client : http_context = raven_context ( ** request ) sentry . captureException ( data = { 'request' : http_context } ) logger . error ( 'RESPONSE %(uuid)s %(method)s %(url)s %(error)s' % dict ( uuid = str ( event [ 'uuid' ] ) , method = request [ 'method' ] , url = request [ 'url' ] , error = exception . message , ) ) data = dict ( parent = str ( event [ 'uuid' ] ) , error = exception . message , started_at = started_at , ended_at = time ( ) , ) webhook_ran . send ( None , data = data ) return data
Build request from event,webhook,payoad and parse response.