in main.py [0:0]
def process_pubsub(event,
context,
message_too_old_exception=False,
using_webserver=False):
"""Function that is triggered by Pub/Sub incoming message.
Args:
event (dict): The dictionary with data specific to this type of
event. The `data` field contains the PubsubMessage message. The
`attributes` field will contain custom attributes if there are any.
context (google.cloud.functions.Context): The Cloud Functions event
metadata. The `event_id` field contains the Pub/Sub message ID. The
`timestamp` field contains the publish time.
"""
global execution_count, configuration, logger
execution_count += 1
if not logger:
logger = setup_logging()
if using_webserver:
logger.debug('Received an API call.',
extra={
'event_id': context.event_id,
'timestamp': context.timestamp,
'hostname': socket.gethostname(),
'pid': os.getpid(),
'execution_count': execution_count
})
else:
logger.debug('Received a Pub/Sub message.',
extra={
'event_id': context.event_id,
'timestamp': context.timestamp,
'hostname': socket.gethostname(),
'pid': os.getpid(),
'execution_count': execution_count
})
socket.setdefaulttimeout(10)
if not configuration:
configuration = load_configuration(config_file_name)
try:
decode_and_process(logger, configuration, event, context,
using_webserver)
except TemplateError as exc:
logger.error('Error while evaluating a Jinja2 template!',
extra={
'error_message': exc,
'error': str(exc),
})
raise exc
except MessageTooOldException as mtoe:
if not message_too_old_exception:
pass
else:
raise (mtoe)